Hi all,
I need to geocode 100 addresses from google maps, but if I iterate an array with a simple for loop, google maps stop all my request with a "OVER_QUERY_LIMIT" because te request are too fast.
What I want to get is to send a single request to google maps every 5 seconds but I don't know how to iterate avery item of my array every 5 seconds.
Any help or idea?
This is my code:
- $(document).ready(function(){
- geocoder = new google.maps.Geocoder();
- var addresses = [" example address 1"," example address 2"," example address N"];
-
- // This code does work too fast and I need to extract an item every 5 second and send it to the codeAddress function.
- for (i = 0; i < addresses.length; i++) {
- codeAddress(addresses[i]);
- }
- });
- function codeAddress(address) {
- geocoder.geocode( { 'address': address}, function(results, status) {
- if (status == google.maps.GeocoderStatus.OK) {
- console.log('Lat'+results[0].geometry.location.b + ' - Lng:' + results[0].geometry.location.c);
- } else {
- console.log("Geocode was not successful for the following reason: " + status);
- }
- });
- }