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是我的脚本,可以在focusin
文本字段name ='location'
上显示自动填充功能。这很好。只是,我已经删除了一堆geocoder
代码,提醒输入位置的状态,即:ZERO_RESULTS。
但它保持警报,QUERY OVER LIMIT,ZERO_RESULT消息。我不知道提示这些消息的位置,因此如何阻止它?
答案 0 :(得分:3)
您需要从geocodeAddress函数开始。
你的功能可能会喜欢这个
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
}
}
);
}
您必须在地理编码处理程序中使用错误状态发出警报。 所以,你应该修改处理程序代码。