<script>
// Note: This example requires that you consent to location sharing when
// prompted by your browser. If you see the error "The Geolocation service
// failed.", it means you probably did not give permission for the browser to
// locate you.

function initMap() {
  var myLatLng = {lat: 19.711491, lng: -101.163486};

  var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 17,
    center: myLatLng
  });

  var geocoder = new google.maps.Geocoder();

  var almacen = '<?php echo base_url(); ?>assets/images/almacen.png';

  var marker = new google.maps.Marker({
    position: myLatLng,
    map: map,
    title: 'CEDIS',
    icon: almacen
  });

  var json = '<?php echo $this->util->getSucursalMapa(); ?>';
  var arr = JSON.parse(json);

  for (var k in arr) {

    var delay=50000; //1 second

    setTimeout(geocodeAddress(geocoder, map, arr[k].address, arr[k].title), delay);

    //geocodeAddress(geocoder, map, arr[k].tittle.address, arr[k].tittle);
  }

  

}


function geocodeAddress(geocoder, resultsMap, address, title) {

  geocoder.geocode({'address': address}, function(results, status) {
    if (status === google.maps.GeocoderStatus.OK) {
      resultsMap.setCenter(results[0].geometry.location);

      var hospital = '<?php echo base_url(); ?>assets/images/hospital.png';

      var marker = new google.maps.Marker({
        map: resultsMap,
        position: results[0].geometry.location,
        title: title,
        icon: hospital
      });

    } else {
      console.log('Geocode was not successful for the following reason: ' + status + ', ' + title + ', ' + address);
    }
  });
}

</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDBWCwncsQCsHn8HiorEIPAfpCSCvQRClo&signed_in=true&callback=initMap"
async defer>
</script>
