Question

I have noticed that my geocoder is inconsistent in the code shown below because before the "getLatLng" method is called I show 10 valid locations, but after this line of code the number of points that actually show up is different each time I search (same search criteria - fyi) Between 5 and 10 at random .. very strange

Anyone have issues similar to 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);
Was it helpful?

Solution 4

I actually found that it wasn't the "verify address" code that was causing this inconsistency, but instead - just the fact that the maps api didn't want a ton of geocoder calls so I added a simple 225ms timeout between each request and this 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);
    }

OTHER TIPS

I've seen this in my ASP.NET app. My issue was that I was validating the addresses before displaying them and

  1. Some of my addresses were incorrect.

  2. Their address validation system can only handle a certain amount of requests on every call by a client.

It's better off scrubbing the addresses before geocoding (IMO).

Try verifying your addresses and also try limiting the amount of addresses you send just to test and see if that's consecutive for every request.

Hope that helps.

Give it a try like this, like this i get over 34 points with one run:

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
      }
    }
  );
}  

I am not sure what the addPreCount() does. But I think it's obvious that the timeout should be something like index multiplied by the actual timeout constant.

So assuming the timeout constant defined is 225. The timeout to be passed to the geocoder wrapper would be:

var timeout = [index_of_each_xaddr] * 225;
window.setTimeout(function() { geoCodeLookup(_xaddr, _xid, _xindex, _xhtml, _xstatus); }, timeout);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top