1

i am using following function to load latlng of addresses From an array to array about 40, but it stops after 10 iterations.

 loadStoreLatLong(40);


   function loadStoreLatLong(i){     


    var paddress = store_locations[i]['address'] +','+store_locations[i]['postal_code'] + ', ' +store_locations[i]['district'] + ',' + store_locations[i]['country'];
    var  pgeocoder = new google.maps.Geocoder();

    pgeocoder.geocode( { 'address': paddress}, function(results, status) {  
        if (status == google.maps.GeocoderStatus.OK) {

        Storelatlong[i] = results[0].geometry.location;
        i--;

        if(i<0){

   clientLocation();

        }else{

   loadStoreLatLong(i);

    //var t = setTimeout("loadStoreLatLong("+(i)+")",1000);
    //jQuery('#map_canvas').text('Loading ... '+i);

        }
        }
    });
}

i am really stuck there, can any one help to figure it out, when i set time out 1000, this iterates fine 40 time, when i decrease the timeout, iterations also decreases and stop. thanks

Asif hhh
  • 1,552
  • 3
  • 15
  • 27

2 Answers2

0

Geocoder of Google Maps API Javascript is not suite for much points. They denies continuous accesses in short time.

So please use REST version even if you have 40 points. https://developers.google.com/maps/documentation/geocoding/

wf9a5m75
  • 6,100
  • 3
  • 25
  • 59
  • "use REST version" i dont understand, can you please guide a bit. some short example. – Asif hhh Nov 29 '12 at 07:31
  • How many points do you have? If there are a little points, you can geocoding manually. http://gmaps-samples.googlecode.com/svn/trunk/geocoder/singlegeocode.html – wf9a5m75 Nov 29 '12 at 18:13
0

The client geocoder is not intended for geocoding lots of points on page load. It is intended for geocoding user entered addresses.

It is asynchronous and is subject to a quota and rate limit. The limits are set up such that you can geocode ~10 points quickly (depending on server load).

You should check the status returned, if it indicates that you are over the limit, delay for a period of time and retry.

See Andrew's answer to this question

Community
  • 1
  • 1
geocodezip
  • 158,664
  • 13
  • 220
  • 245
  • Is there any other library or service that can quick, or any other way ? – Asif hhh Nov 29 '12 at 11:06
  • The usual suggestion is to geocode the points offline (not on page load) and use the resulting coordinates, not the geocoder, on page load. – geocodezip Nov 29 '12 at 11:15
  • i have to get points on page load, load all addresses in array and then through loop find latlng of these addresses. can you give me an example, for coordinates and do this will not make issue ? – Asif hhh Nov 30 '12 at 05:40