如何防止谷歌的地理编码警报状态消息
How to prevent Google's geocode alert status message?
function initMap() {
var this_input;
/* var options = {
types: ['(cities)'],
componentRestrictions: {country: "my"}
};*/
$("input[name=location]").focusin(function(){
// alert($(this).attr("id"));
this_input = $(this).attr("id");
var input = /** @type {!HTMLInputElement} */(
document.getElementById(this_input));
var autocomplete = new google.maps.places.Autocomplete(input);
var infowindow = new google.maps.InfoWindow();
var geocoder = new google.maps.Geocoder();
autocomplete.addListener('place_changed', function() {
infowindow.close();
var place = autocomplete.getPlace();
if (!place.geometry) {
window.alert("Autocomplete's returned place contains no geometry");
return;
}
var address = '';
if (place.address_components) {
address = [
(place.address_components[0] && place.address_components[0].short_name || ''),
(place.address_components[1] && place.address_components[1].short_name || ''),
(place.address_components[2] && place.address_components[2].short_name || '')
].join(' ');
}
infowindow.setContent('<div><strong>' + place.name + '</strong><br>' + address);
});
document.getElementById('submit').addEventListener('click', function() {
geocodeAddress(geocoder);
});
});//end of input[name=location]
}
ABove 是我的脚本,用于在带有name ='location'
的任何focusin
文本字段上显示自动完成。这工作正常。只是,我已经删除了一堆geocoder
代码,提醒输入位置的状态,即:ZERO_RESULTS。
但它会不断发出警报、超出限制的查询ZERO_RESULT消息。我不知道这些消息是从哪里提示的,因此我该如何阻止它?
您需要从地理编码地址函数开始。
你的函数可能会喜欢这个
function geocodeAddress(geo) {
geo.geocode({address:search}, function (results, status)
{
// If that was successful
if (status == google.maps.GeocoderStatus.OK) {
...
}
// ====== Decode the error status ======
else {
// Make alert when error occurs
window.alert(status); // <-- delete this line or modify it
}
}
);
}
您必须在地理编码处理程序中使用错误状态发出警报。因此,您应该修改处理程序代码。
相关文章:
- 显示服务工作者状态的消息
- 如何在 jquery 中的速率按钮下方显示消息状态
- 如何在php中添加按钮而不是错误状态和成功消息
- 谷歌地图叠加层消息不会保持隐藏状态
- 日志消息,如果 Api 服务状态 == 404 在角度 JS
- 将焦点设置在带有错误消息的第一个输入元素上,并将包含它的 TabStrip 选项卡设置为活动状态
- 有没有办法使用Flexigrid显示有吸引力的“空状态”消息
- YDN:Firefox 版本 44 上出现消息无效状态错误的错误
- 如何防止谷歌的地理编码警报状态消息
- 方法POST,状态(已取消)错误消息
- 复选框确认消息-如果为false,则保持选中状态
- 芹菜+Django——使用Django消息框架轮询任务状态和报告成功或失败
- 在Rails中,如何在视图中显示控制器操作成功或失败的JSON状态消息
- Ajax响应状态为200,但显示错误消息
- 如何通过主干视图渲染持久化状态消息/图标/通知
- 这是在asp.net中显示状态消息的最佳方式
- jQuery ajax自定义HTTP状态消息在2xx范围内
- php显示登录状态消息不更新
- 如何使用angular js动态更改网页上各种结果的状态消息
- 最佳jQuery状态消息插件