var iconBase = 'https://developers.google.com/maps/documentation/javascript/examples/full/images/';

var data = [
    {
      position: {lng: -66.056812, lat: 18.415312},
      title: "Centro de Ayuda a Víctimas de Violación"
    },
    {
      position: {lng: -66.227438, lat: 18.218187},
      title: "Casa Juana Colón"
    },
    {
      position: {lng: -66.265938, lat: 18.140312},
      title: "Envejecer en Armonía"
    },
    {
      position: {lng: -66.703438, lat: 18.265812},
      title: "Fundación Alas a la Mujer"
    },
    {
      position: {lng: -66.740563, lat: 18.444438},
      title: "Oficina para Promoción y Desarrollo Humano"
    },
    {
      position: {lng: -66.051063, lat: 18.219813},
      title: "Centro Salud Justicia de Puerto Rico"
    },
    {
      position: {lng: -66.051687, lat: 18.412188},
      title: "Centro Comunitario LGBT"
    },
    {
      position: {lng: -65.833312, lat: 18.422687},
      title: "Taller Salud"
    },
    {
      position: {lng: -66.075187, lat: 18.399687},
      title: "Profamilias"
    },
    {
      position: {lng: -66.056437, lat: 18.402188},
      title: "Instituto del Hogar Celia y Harrys Bunker, Proyecto Criando para la Paz"
    },
    {
      position: {lng: -66.052188, lat: 18.403937},
      title: "Centro de Apoyo para Víctimas el Crimen"
    },
    {
      position: {lng: -66.058062, lat: 18.427938},
      title: "Oficina de la Procuradora de las Mujeres"
    },
    {
      position: {lng: -66.074562, lat: 18.396437},
      title: "Instituto de Deficiencias en el Desarrollo, UPR RCM"
    },
    {
      position: {lng: -67.139813, lat: 18.212188},
      title: "Proyecto Apoyo a Mujeres Sobrevivientes de Violencia Doméstica, Siempre Vivas, UPRM"
    }

];
  
  
  var app = {
      // Application Constructor
      initialize: function() {
          document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
      },
  
      // deviceready Event Handler
      //
      // Bind any cordova events here. Common events are:
      // 'pause', 'resume', etc.
      onDeviceReady: function() {
          this.receivedEvent('deviceready');
      },
  
      // Update DOM on a Received Event
      receivedEvent: function(id) {
          navigator.geolocation.getCurrentPosition(onMapSuccess, onMapError, { enableHighAccuracy: true });
          
      }
      
  };
  
  app.initialize();
  
  // Success callback for get geo coordinates
  
  var onMapSuccess = function (position) {
  
      Latitude = position.coords.latitude;
      Longitude = position.coords.longitude;
  
      getMap(Latitude, Longitude);
  
  }
  
  function getMap(Latitude, Longitude){
      var latLong = new google.maps.LatLng(Latitude, Longitude);
  
       var mapOptions = {
          center: latLong,
          zoom: 8,
          mapTypeId: google.maps.MapTypeId.ROADMAP
      };
      //MAPA
      var map = new google.maps.Map(document.getElementById("map"), mapOptions);
      

    //MARKERS
     var contentString = '<div id="content">'+
     '<div id="siteNotice">'+
     '</div>'+
     '<h1 id="firstHeading" class="firstHeading">Centro de Ayuda a Víctimas de Violación</h1>'+
     '<p>Attribution: Uluru, <a href="https://www.google.com/maps/dir/?api=1&origin=' + latLong + '&destination=' + data[0]['title'] + '>"'
     'Get Directions</a> '+
     '(last visited June 22, 2009).</p>'+
     '</div>';


     var infowindow = new google.maps.InfoWindow({
        content: contentString,
        maxWidth: 200
      });
    
      var marker = new google.maps.Marker({position: data[0]['position'], title: data[0]['title'], map: map});
      marker.addListener('click', function() {
        infowindow.open(map, marker);
      });

      /////////////////////////////////////////////////////////////////////////////

      var contentString1 = '<div id="content">'+
     '<div id="siteNotice">'+
     '</div>'+
     '<h1 id="firstHeading" class="firstHeading">Casa Juana Colón</h1>'+
     '<div id="bodyContent">'+
     '<p>Attribution: Uluru, <a href="https://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
     'https://en.wikipedia.org</a> '+
     '(last visited June 22, 2009).</p>'+
     '</div>';

      var infowindow1 = new google.maps.InfoWindow({
        content: contentString1,
        maxWidth: 200
      });

      var marker1 = new google.maps.Marker({position: data[1]['position'], title: data[1]['title'],map: map});
      marker1.addListener('click', function() {
        infowindow1.open(map, marker1);
      });

      ////////////////////////////////////////////////////////////////////////////////

      var contentString2 = '<div id="content">'+
     '<div id="siteNotice">'+
     '</div>'+
     '<h1 id="firstHeading" class="firstHeading">Envejecer en Armonía</h1>'+
     '<div id="bodyContent">'+
     '<p>Attribution: Uluru, <a href="https://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
     'https://en.wikipedia.org</a> '+
     '(last visited June 22, 2009).</p>'+
     '</div>';

      var infowindow2 = new google.maps.InfoWindow({
        content: contentString2,
        maxWidth: 200
      });

      var marker2 = new google.maps.Marker({position: data[2]['position'], title: data[2]['title'],map: map});
      marker2.addListener('click', function() {
        infowindow2.open(map, marker2);
      });

      /////////////////////////////////////////////////////////////////////////////////
      var contentString3 = '<div id="content">'+
     '<div id="siteNotice">'+
     '</div>'+
     '<h1 id="firstHeading" class="firstHeading">Fundación Alas a la Mujer</h1>'+
     '<div id="bodyContent">'+
     '<p>Attribution: Uluru, <a href="https://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
     'https://en.wikipedia.org</a> '+
     '(last visited June 22, 2009).</p>'+
     '</div>';

      var infowindow3 = new google.maps.InfoWindow({
        content: contentString3,
        maxWidth: 200
      });

      var marker3 = new google.maps.Marker({position: data[3]['position'], title: data[3]['title'],map: map});
      marker3.addListener('click', function() {
        infowindow3.open(map, marker3);
      });

      ////////////////////////////////////////////////////////////////////////////////////
      var contentString4 = '<div id="content">'+
     '<div id="siteNotice">'+
     '</div>'+
     '<h1 id="firstHeading" class="firstHeading">Oficina para Promoción y Desarrollo Humano</h1>'+
     '<div id="bodyContent">'+
     '<p>Attribution: Uluru, <a href="https://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
     'https://en.wikipedia.org</a> '+
     '(last visited June 22, 2009).</p>'+
     '</div>';

      var infowindow4 = new google.maps.InfoWindow({
        content: contentString4,
        maxWidth: 200
      });

      var marker4 = new google.maps.Marker({position: data[4]['position'], title: data[4]['title'],map: map});
      marker4.addListener('click', function() {
        infowindow4.open(map, marker4);
      });

      //////////////////////////////////////////////////////////////////////////////////
      var contentString5 = '<div id="content">'+
      '<div id="siteNotice">'+
      '</div>'+
      '<h1 id="firstHeading" class="firstHeading">Centro Salud Justicia de Puerto Rico</h1>'+
      '<div id="bodyContent">'+
      '<p>Attribution: Uluru, <a href="https://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
      'https://en.wikipedia.org</a> '+
      '(last visited June 22, 2009).</p>'+
      '</div>';
 
       var infowindow5 = new google.maps.InfoWindow({
         content: contentString5,
         maxWidth: 200
       });

      var marker5 = new google.maps.Marker({position: data[5]['position'], title: data[5]['title'],map: map});
      marker5.addListener('click', function() {
        infowindow5.open(map, marker5);
      });
      //////////////////////////////////////////////////////////////////////////////////
      var contentString6 = '<div id="content">'+
      '<div id="siteNotice">'+
      '</div>'+
      '<h1 id="firstHeading" class="firstHeading">Centro Comunitario LGBT</h1>'+
      '<div id="bodyContent">'+
      '<p>Attribution: Uluru, <a href="https://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
      'https://en.wikipedia.org</a> '+
      '(last visited June 22, 2009).</p>'+
      '</div>';
 
       var infowindow6 = new google.maps.InfoWindow({
         content: contentString6,
         maxWidth: 200
       });
      var marker6 = new google.maps.Marker({position: data[6]['position'], title: data[6]['title'],map: map});
      marker6.addListener('click', function() {
        infowindow6.open(map, marker6);
      });
      //////////////////////////////////////////////////////////////////////////////////
      var contentString7 = '<div id="content">'+
      '<div id="siteNotice">'+
      '</div>'+
      '<h1 id="firstHeading" class="firstHeading">Taller Salud</h1>'+
      '<div id="bodyContent">'+
      '<p>Attribution: Uluru, <a href="https://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
      'https://en.wikipedia.org</a> '+
      '(last visited June 22, 2009).</p>'+
      '</div>';
 
       var infowindow7 = new google.maps.InfoWindow({
         content: contentString7,
         maxWidth: 200
       });

      var marker7 = new google.maps.Marker({position: data[7]['position'], title: data[7]['title'],map: map});
      marker7.addListener('click', function() {
        infowindow7.open(map, marker7);
      });
      //////////////////////////////////////////////////////////////////////////////////

      var contentString8 = '<div id="content">'+
      '<div id="siteNotice">'+
      '</div>'+
      '<h1 id="firstHeading" class="firstHeading">Profamilias</h1>'+
      '<div id="bodyContent">'+
      '<p>Attribution: Uluru, <a href="https://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
      'https://en.wikipedia.org</a> '+
      '(last visited June 22, 2009).</p>'+
      '</div>';
 
       var infowindow8 = new google.maps.InfoWindow({
         content: contentString8,
         maxWidth: 200
       });

      var marker8 = new google.maps.Marker({position: data[8]['position'], title: data[8]['title'],map: map});
       marker8.addListener('click', function() {
        infowindow8.open(map, marker8);
      });      
      //////////////////////////////////////////////////////////////////////////////////
      var contentString9 = '<div id="content">'+
      '<div id="siteNotice">'+
      '</div>'+
      '<h1 id="firstHeading" class="firstHeading">Instituto del Hogar Celia y Harrys Bunker, Proyecto Criando para la Paz</h1>'+
      '<div id="bodyContent">'+
      '<p>Attribution: Uluru, <a href="https://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
      'https://en.wikipedia.org</a> '+
      '(last visited June 22, 2009).</p>'+
      '</div>';
 
       var infowindow9 = new google.maps.InfoWindow({
         content: contentString9,
         maxWidth: 200
       });

      var marker9 = new google.maps.Marker({position: data[9]['position'], title: data[9]['title'],map: map})
      marker9.addListener('click', function() {
        infowindow9.open(map, marker9);
      });  
    

    /////////////////////////////////////////////////////////////////////////////////////
    var contentString10 = '<div id="content">'+
      '<div id="siteNotice">'+
      '</div>'+
      '<h1 id="firstHeading" class="firstHeading">Centro de Apoyo para Víctimas el Crimen</h1>'+
      '<div id="bodyContent">'+
      '<p>Attribution: Uluru, <a href="https://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
      'https://en.wikipedia.org</a> '+
      '(last visited June 22, 2009).</p>'+
      '</div>';
 
       var infowindow10 = new google.maps.InfoWindow({
         content: contentString10,
         maxWidth: 200
       });

      var marker10 = new google.maps.Marker({position: data[10]['position'], title: data[10]['title'],map: map})
      marker10.addListener('click', function() {
        infowindow10.open(map, marker10);
      });  

      ////////////////////////////////////////////////////////////////////////////////////////
      var contentString11 = '<div id="content">'+
      '<div id="siteNotice">'+
      '</div>'+
      '<h1 id="firstHeading" class="firstHeading">Oficina de la Procuradora de las Mujeres</h1>'+
      '<div id="bodyContent">'+
      '<p>Attribution: Uluru, <a href="https://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
      'https://en.wikipedia.org</a> '+
      '(last visited June 22, 2009).</p>'+
      '</div>';
 
       var infowindow11 = new google.maps.InfoWindow({
         content: contentString11,
         maxWidth: 200
       });

      var marker11 = new google.maps.Marker({position: data[11]['position'], title: data[11]['title'],map: map})
      marker11.addListener('click', function() {
        infowindow11.open(map, marker11);
      });  

      

      /////////////////////////////////////////////////////////////////////////////////////////////

      var contentString12 = '<div id="content">'+
      '<div id="siteNotice">'+
      '</div>'+
      '<h1 id="firstHeading" class="firstHeading">Instituto de Deficiencias en el Desarrollo, UPR RCM</h1>'+
      '<div id="bodyContent">'+
      '<p>Attribution: Uluru, <a href="https://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
      'https://en.wikipedia.org</a> '+
      '(last visited June 22, 2009).</p>'+
      '</div>';
 
       var infowindow12 = new google.maps.InfoWindow({
         content: contentString12,
         maxWidth: 200
       });

      var marker12 = new google.maps.Marker({position: data[12]['position'], title: data[12]['title'],map: map})
      marker12.addListener('click', function() {
        infowindow12.open(map, marker12);
      });  

      //////////////////////////////////////////////////////////////////////////////////////////////

      var contentString13 = '<div id="content">'+
      '<div id="siteNotice">'+
      '</div>'+
      '<h1 id="firstHeading" class="firstHeading">Proyecto Apoyo a Mujeres Sobrevivientes de Violencia Doméstica, Siempre Vivas, UPRM</h1>'+
      '<div id="bodyContent">'+
      '<p>Attribution: Uluru, <a href="https://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
      'https://en.wikipedia.org</a> '+
      '(last visited June 22, 2009).</p>'+
      '</div>';
 
       var infowindow13 = new google.maps.InfoWindow({
         content: contentString13
         
        });

      var marker13 = new google.maps.Marker({position: data[13]['position'], title: data[13]['title'],map: map})
      marker13.addListener('click', function() {
        infowindow13.open(map, marker13);
      });  
    }
  
  // Error callback
  
  function onMapError(error) {
      console.log('code: ' + error.code + '\n' +
          'message: ' + error.message + '\n');
  }
  