Google map geocoding stops, while executing recursively

前提是你 提交于 2019-12-11 04:45:36

问题


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


回答1:


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




回答2:


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/



来源:https://stackoverflow.com/questions/13619409/google-map-geocoding-stops-while-executing-recursively

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!