I need some help about my development google map. Indeed, when i try to geocode one address, google gives me all information without problem.
But when i try to geocode several address, it's finish google doesn't answer and I have no reponse.
My code :
$.ajax({
type: "POST",
url: _URL_SITE + "webservices...",
dataType: "xml",
data: parameters,
//contentType: "application/soap+xml; charset=utf-8",
contentType: "text/xml; charset=utf-8",
headers: {
Accept: '*',
SOAPAction: 'http://127.0.0.1/...'
},
success: function (xml) {
var arr = new Array(30000)
var cpt = 1
var address = [];
var address_id = [];
var codepostal = "";
var i = 0;
$(xml).find('Table').each(function () {
codepostal = $(this).find('cp').text();
address[i] = $(this).find('record_id').text() + '|' + codepostal.substring(0,3) + '* ' + $(this).find('commune').text() + '' + '';
i++;
}); // fin de la fonction jquery
traitement(address);
},
error: function () {
alert('error');
}
});
and here the function which resquest google :
function traitement(addresses, callback) {
var coords = [];
var ville = "";
var cp = "";
var lattitude;
var longitude;
for (var i = 0; i < 50; i++) {
currAddress = addresses[i].split("|");
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': currAddress[1] }, function (results, status) {
if (status == 'OK') {
var coords = results[0].geometry.location
lattitude = coords.lat();
longitude = coords.lng();
var latlng = new google.maps.LatLng(lattitude, longitude);
geocoder.geocode({ 'latLng': latlng }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var elt = results[0].address_components;
for (i in elt) {
if (elt[i].types[0] == 'postal_code')
cp = elt[i].short_name;
if (elt[i].types[0] == 'sublocality')
ville = elt[i].short_name;
if (ville == "") {
if (elt[i].types[0] == 'locality')
ville = elt[i].short_name;
}
}
// function which save google's information
Save(currAddress[0], cp, ville, longitude, lattitude)
return;
} else { alert("error lat long"); }
});
} else { alert("error adresse"); }
return;
});
}
I have read some posts about asynchrone request etc. But I'm trying to understand why google gives me 0 answer when iteration of my loop "for" is over 50 repetions.
Thans you.
You are using Geocoding service of Maps JavaScript API. The services in JavaScript API also have a per session limit. The documentation says:
Service requests are rate-limited per user session, regardless of how many users share the same project. When you first load the service API, you are allocated an initial quota of requests. Once you use this quota, the API enforces rate limits on additional requests on a per-second basis. If too many requests are made within a certain time period, the API returns an OVER_QUERY_LIMIT response code. The per-session rate limit prevents the use of client-side services for batch requests. For batch requests, use the Maps API web services.
https://developers.google.com/maps/documentation/javascript/usage
Initially you have a bucket of 10 queries. Once you have used these queries you have to send 1 query per second to stay within allowed user session limits.