-1

In jquery using gmap [jQuery FN Google Map 3.0-rc] I am trying to search multiple locations by displaying it as markers from the current location? How to do it? The code to search a string as below gives only one result whereas google maps gives a lot of markers.

Code:

navigator.geolocation.getCurrentPosition (function(position) {           
var clientPosition = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
//console.log(clientPosition);
$('#map_canvas').gmap({'center': clientPosition, 'zoom': 10, 'disableDefaultUI':true, 'callback': function() {           
          var self = this;           
          self.search({'address' : 'SBI Bank, Bangalore, Karnataka, India'},function(results,status){
              if(status == 'OK')
               {
                  console.log(results);
                  self.addMarker({ 'position': results[0].geometry.location}, function(map,marker){
                      console.log('Inside marker');
                  });
               }                          
          });
      }});
});
vinod
  • 8,350
  • 9
  • 32
  • 36

2 Answers2

0

There is no mystery about it, just repeat:

self.search({'address' : 'SBI Bank, Bangalore, Karnataka, India'},function(results,status){
              if(status == 'OK')
               {
                  console.log(results);
                  self.addMarker({ 'position': results[0].geometry.location}, function(map,marker){
                      console.log('Inside marker');
                  });
               }                          
          });

Number of times, only changing the address search. You can put this structure into a loop if you want.

Walter Gandarella
  • 107
  • 2
  • 4
  • 13
0

Thank Walter. But, the best way is to use the Google API 'https://maps.googleapis.com/maps/api/place/search/xml?location='+ latlong +'&radius=10000&types='+searchType+'&sensor=false&name=ABC&key=AIzaSyA8NKZp03E7Nk0P39nj9nrckPdvqYL38Y4' which return the results in xml or JSON [change place/search/xml to place/search/json] and from that we can add markers

vinod
  • 8,350
  • 9
  • 32
  • 36