Issue in plotting multiple markers

172 views
Skip to first unread message

sandeesh phulkar

unread,
May 3, 2011, 5:36:19 AM5/3/11
to google-map...@googlegroups.com
I have a set of addresses which i want to plot on Google Map.
This is the code i have written:-

var geocoder = new google.maps.Geocoder();
var map = new google.maps.Map(document.getElementById("map"), myOptions);
// I have about 50 addresses in address2[]

for (var i=0;i<address2.length;i++){
  geocoder.geocode( { address: address2[i]}, function(results, status) {

// 1. alert('Hi');
    if (status == google.maps.GeocoderStatus.OK) {
           map.setCenter(results[0].geometry.location);
           marker = new google.maps.Marker({
            position: results[0].geometry.location,
            map: map,
            title: ""
        });
     }
  
  });
 
 }   


The issue which I am facing is:-
Not all of the addresses are getting plotted.
Only the first 11 addresses are getting plotted with the marker...

But if I include an alert as shown in the code.(alert('Hi'));
It gives me an alert before plotting every address and all the 50 addreses are plotted.
Any Suggestions????

I also tried using SetTimeout function for the callback function of geoocoder.goecode().But it didnt work :-(
Thanks in advance.
 
 

geoco...@gmail.com

unread,
May 3, 2011, 9:07:38 AM5/3/11
to Google Maps JavaScript API v3
On May 3, 2:36 am, sandeesh phulkar <sandypassi...@gmail.com> wrote:
> I have a set of addresses which i want to plot on Google Map.
> This is the code i have written:-
>
> var geocoder = new google.maps.Geocoder();
> var map = new google.maps.Map(document.getElementById("map"), myOptions);
> // I have about 50 addresses in address2[]
>
> for (var i=0;i<address2.length;i++){
>   geocoder.geocode( { address: address2[i]}, function(results, status) {
>
> // 1. alert('Hi');
>     if (status == google.maps.GeocoderStatus.OK) {
>            map.setCenter(results[0].geometry.location);
>            marker = new google.maps.Marker({
>             position: results[0].geometry.location,
>             map: map,
>             title: ""
>         });
>      }
>
>   });
>
>  }    
>
> The issue which I am facing is:-
> Not all of the addresses are getting plotted.
> Only the first 11 addresses are getting plotted with the marker...
>
> But if I include an alert as shown in the code.(alert('Hi'));
> It gives me an alert before plotting every address and all the 50
> addreses are plotted.
> Any Suggestions????

Geocoding is subject to quotas and rate limits. Don't geocode
addresses everytime your page loads, geocode them off line and use the
coordinates to plot the markers. Only use the geocoder for "user"
entered points.

See this "article":
http://code.google.com/apis/maps/articles/geocodestrat.html

-- Larry
Reply all
Reply to author
Forward
0 new messages