Google Maps API - GClientGeocoder inconsistency using getLatLng method?

I noticed that my geocoder is incompatible in the code shown below because before the getLatLng method is called, I am showing 10 correct locations, but after this line of code, the number of points that are actually displayed is different every time I search (same search criteria - fyi) Between 5 and 10 in random order .. very strange

Anyone have problems like this? If so, how did you solve them?

geocoder = new GClientGeocoder();
geocoder.getLatLng(address, function(point) {
if (point) {
        var icon = new GIcon();
        var marker = new GMarker(point, { icon: icon });
        GEvent.addListener(marker, 'click', function() { marker.openInfoWindowHtml(html); });
        map.addOverlay(marker);

      

0


source to share


4 answers


I did find that it was not the "address check" code that was causing this inconsistency, but instead just the fact that the api maps didn't need a ton of geocoder requests, so I added a simple 225ms timeout between each request, and it did the trick



function preGeoCodeLookup(_xaddr, _xid, _xindex, _xhtml, _xstatus) {
        addPreCount();

        //don't change this timeout as it was the lowest timeout that still worked w/ the api
        var timeout = parseInt(precount) * 225;

        window.setTimeout(function() { geoCodeLookup(_xaddr, _xid, _xindex, _xhtml, _xstatus); }, timeout);
    }

      

0


source


I've seen this in my ASP.NET application. My problem was that I was checking addresses before displaying them and

  • Some of my addresses were wrong.

  • Their address validation system can handle a certain number of requests on each client call.

Better to clean up addresses before geocoding (IMO).



Try to validate your addresses, and also try to limit the number of addresses you submit for testing only and see if that works for each request.

Hope it helps.

+1


source


Give it a try like this, I get over 34 points in one pass:

function addAddress(address,runde) {
  geocoder.getLatLng(
    address,
    function(point) {
      if (!point) {
        //alert(address + " not found");
        if (runde<5) { // rekursiv, try adress 5 times to get
            window.setTimeout(function() {addAddress(address,runde+1);}, 1000); // wait 1 second bevor next try
            }
      } else {
        var marker_add = new GMarker(point);
        //alert(marker.getLatLng());
        leftClick(0, marker_add.getLatLng()); // function, add marker to map
      }
    }
  );
}  

      

+1


source


I'm not sure what it does addPreCount()

. But I think it's obvious that the timeout should be something like an index multiplied by the actual timeout constant.

So, assuming the specific timeout constant is 225. The timeout that needs to be passed to the geocoding shell would be:

var timeout = [index_of_each_xaddr] * 225;
window.setTimeout(function() { geoCodeLookup(_xaddr, _xid, _xindex, _xhtml, _xstatus); }, timeout);

      

+1


source







All Articles