When geocoding over 11 locations using the Google Maps API v3, you may encounter the OVER_QUERY_LIMIT error. This indicates that you are exceeding the rate limit for geocoding requests.
To resolve this error, you need to introduce pauses between geocoding requests.
Here is a modified version of your code that implements a pause after each geocoding request:
<code class="javascript">function codeAddress(vPostCode) { if (geocoder) { setTimeout(function() { geocoder.geocode( { 'address': "'" + vPostCode + "'"}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { map.setCenter(results[0].geometry.location); var marker = new google.maps.Marker({ map: map, position: results[0].geometry.location }); } else { alert("Geocode was not successful for the following reason: " + status); } }); }, 2000); // 2 seconds delay } }</code>
In this code, the setTimeout() function is used to introduce a delay of 2 seconds (2000 milliseconds) between each geocoding request. This ensures that you do not exceed the rate limit imposed by the API.
The above is the detailed content of How to Avoid OVER_QUERY_LIMIT Errors in Google Maps API v3 When Geocoding Multiple Locations?. For more information, please follow other related articles on the PHP Chinese website!