Google地理编码器由于over_query_limit而失败 [英] Google geocoder failing due to over_query_limit
问题描述
我使用反向地理编码来填充四个表单域。表单填写正确,但然后我收到一个错误,指出OVER_QUERY_LIMIT。在检查Chrome的JS控制台时,我看到五个相同的调用在我收到错误消息之前已经完成。我不确定为什么我的代码发出了几个请求。有人能指出我应该在codeLatLng函数的循环中更改什么。这很可能出现问题。
var geocoder;
函数getCity(){
geocoder = new google.maps.Geocoder();
}
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(successFunction,errorFunction);
}
//获取纬度和经度;
函数successFunction(position){
var lat = position.coords.latitude;
var lng = position.coords.longitude;
// alert(成功功能+ lat ++ lng);
codeLatLng(lat,lng)
}
函数errorFunction(){
AppMobi.notification.alert(为了获得最佳的用户体验,请确保您的设备具有GPS并启用地理位置设置。,禁用地理位置,确定);
函数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]){
//格式化地址
//alert (results[0].formatted_address)//完整地址
$(#address1 ).val(results [0] .formatted_address);
} else {
alert(未找到结果,请手动输入数据。);
}
} else {
alert(Geocoder failed due to:+ status +。Please input the data manually。);
}
});
很多预先感谢。
使用Google Maps API网络服务受每天允许的请求数量限制。
OVER_QUERY_LIMIT是由这个限制。
在这里您可以找到更多信息:
https://developers.google.com/maps/documentation/business/articles/usage_limits
你可以尝试等待超过2秒,当谷歌响应这个错误,例如,一个setTimeout。
这可能是结果[0] .address_components [i]将是对函数调用的引用。
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.
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.
这篇关于Google地理编码器由于over_query_limit而失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!