On Wed, Jun 9, 2010 at 23:08, HMM <[email protected]> wrote:

> I am new to using google maps.  I am currently using javascript API v3
> to geocode addresses.  Everything seems to work fine except for the
> OVER_QUERY_LIMIT.  From what I have read, I am geocoding too fast and
> need to put a delay between requests.


First, why are you going so fast? Maybe you would be better off using the
Web Service instead, see this FAQ to get an idea of whether this is the
case:

When should I use an API geocoder class and when should I use the HTTP
Geocoding Service?
http://code.google.com/apis/maps/faq.html#geocoder_classorhttp

 I have tried this but can't
> seem to find the right place for the delay.  I am using the following
> code to geocode the address:
>

If you do need to geocode a lot of things from JavaScript, then put them in
an array and try them one by one, stopping when receiving a OVER_QUERY_LIMIT

You'd need also some variable to flag whether you should wait of not:

var wait = false;

Try this in a loop across your array of things (addresses or coordinates) to
geocode:

if (geocoder) {
>

while (wait) { /* Just wait. This is a nasty way to do it, you may want a
more elaborate one that won't "freeze" your browser. */ };


>      geocoder.geocode( { 'address': address}, function(results,
> status) {
>        if (status == google.maps.GeocoderStatus.OK) {
>          map.setCenter(results[0].geometry.location);
>          var contentString = '<font face=arial size=1>' + address +
> '<br>' + infotext + '</font>';
> var infowindow = new google.maps.InfoWindow({
>                  content: contentString
>                  });
>          var marker = new google.maps.Marker({
>              map: map,
>              position: results[0].geometry.location,
>                          title: address
>          });
>                  google.maps.event.addListener(marker, 'click', function()
> {
>              infowindow.open(map,marker);
>          });
>

/* When geocoding "fails", see if it was because of over quota error: */
} else if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {
  wait = true;
  setTimeout("wait = false", 1000);

       } else {
>            alert("Geocode was not successful for the following
> reason: " + status);

       }
>      });
>    }
>  }
>

I used a 1s. delay just as a random number, but I'd suggest something a bit
more elaborate: start with a small one (e.g. 200ms) and double it each time
you get an OVER_QUERY_LIMIT *after* waiting, e.g.:

- try to geocode something
- recieve OVER_QUERY_LIMIT
- wait 200 ms. and try again
- receive OVER_QUERY_LIMIT
- wait 400 ms. and tray again
....

--
> You received this message because you are subscribed to the Google Groups
> "Google Maps JavaScript API v3" group.
> To post to this group, send email to
> [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-maps-js-api-v3%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-maps-js-api-v3?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps JavaScript API v3" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-maps-js-api-v3?hl=en.

Reply via email to