Reputation: 43
I'm filling four form fields using reverse geocoding. The form fills correctly but then I receive an error stating OVER_QUERY_LIMIT. On checking the JS console of chrome I see that five identical calls have been made before I received the error message. I'm unsure why my code is making several requests. Could someone please point out what I should change in my loops in the codeLatLng function. That's most likely where the problem is.
var geocoder;
function getCity() {
geocoder = new google.maps.Geocoder();
}
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(successFunction, errorFunction);
}
//Get the latitude and the longitude;
function successFunction(position) {
var lat = position.coords.latitude;
var lng = position.coords.longitude;
//alert("Success funciton" + lat + " " + lng);
codeLatLng(lat, lng)
}
function errorFunction(){
AppMobi.notification.alert("For the best user experience, please ensure your device GPS and geolocation settings are enabled.","Geolocation disabled","OK");
}
function codeLatLng(lat, lng) {
//alert("codeLatLng fn started");
var latlng = new google.maps.LatLng(lat, lng);
geocoder.geocode({'latLng': latlng}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
console.log(results)
if (results[1]) {
//formatted address
//alert(results[0].formatted_address) //Complete address
$("#address1").val(results[0].formatted_address);
} else {
alert("No results found. Please enter the data manually.");
}
} else {
alert("Geocoder failed due to: " + status +". Please enter the data manually." );
}
});
Many Thanks in advance.
Upvotes: 4
Views: 22765
Reputation: 3886
Use of the Google Maps API Web Services is subject to specific limits on the amount of requests per day allowed.
OVER_QUERY_LIMIT is caused by this restriction.
Here you can find more information:
https://developers.google.com/maps/documentation/business/articles/usage_limits
You can try to wait over 2 seconds when google responds with this error, for example, with a setTimeout.
It could be that results[0].address_components[i] will be a reference to a function call.
Upvotes: 3