lundi 23 novembre 2015

Multiple Markers in GoogleMaps Javascript+Laravel

I am trying to build a simple "storelocator" where I pass the search key and return the nearby address on the map. For this I am using Javascript and Laravel Eloquent. I am able to see the map but not the markers. Please suggest me what should I do?

 <script>
  var locations =  <?php echo $address_markes ?>  ;
  var lat = 22.54430389404;
  var lng = 88.36476135254;
  var map = new google.maps.Map(document.getElementById('map-canvas'),{
    center:{
      lat: lat,
      lng: lng
    },
    zoom: 15
  });

  var marker, i;

  for (i = 0; i < locations.length; i++) {  
      marker = new google.maps.Marker({
        position: new google.maps.LatLng(locations[i][1], locations[i][2]),
        map: map
      });

      google.maps.event.addListener(marker, 'click', (function(marker, i) {
        return function() {
          infowindow.setContent(locations[i][0]);
          infowindow.open(map, marker);
        }
      })(marker, i));
    }
  /*var marker =  new google.maps.Marker({
    position:{
      lat:lat,
      lng: lng
    },
    map:map
  });*/

  </script>

when I click on view source, I see this :

var locations = [{"dealership_name":"Shyam Motors","lat":22.544303894,"lng":88.3647613525},{"dealership_name":"Das Auto","lat":22.5396156311,"lng":88.3710708618}] ; var lat = 22.54430389404; var lng = 88.36476135254; var map = new google.maps.Map(document.getElementById('map-canvas'),{ center:{ lat: lat, lng: lng }, zoom: 15 });

var marker, i;

for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({ position: new google.maps.LatLng(locations[i][1], locations[i][2]), map: map });

  google.maps.event.addListener(marker, 'click', (function(marker, i) {
    return function() {
      infowindow.setContent(locations[i][0]);
      infowindow.open(map, marker);
    }
  })(marker, i));
}   /*var marker =  new google.maps.Marker({
position:{
  lat:lat,
  lng: lng
},
map:map   });*/
 </script>

So where am I going wrong ? Please guide.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire