tags:

views:

4084

answers:

4

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);
+1  A: 

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.

Saif Khan
So if I remove the verify line of code if (point) { ... does this do the verify you are talking about or ?
Toran Billups
Your code seems fine. I think your address are incorrect. Try plotting a few corrected addresses several times and see if you get the same results.
Saif Khan
A: 

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);
    }
Toran Billups
A: 

Hi Toran,

could you explain more about adding the timeout section? that's the definition of addPreCount() function? what's the value of precount? Thanks.

REgard, Wely

Wely