【发布时间】:2015-05-21 14:40:34
【问题描述】:
我正在尝试创建一个简单的应用程序,在其中插入搜索区域、搜索内容和搜索半径。我不明白为什么它只在我第二次执行查询搜索时才能正常工作,我知道问题可能出在我的 codeAddress() 函数中:
function codeAddress(){
var address = document.getElementById('Zona').value;
geocoder.geocode( { 'address': address}, function(results, status){
if (status == google.maps.GeocoderStatus.OK){
map.setCenter(results[0].geometry.location);
coordo = results[0].geometry.location;
}else{
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
由于某种原因,我不知道它会跳过,并且不会进入 geocoder.geocode( { 'address': address}, function(results, status) 内部,但如果这是我第二次执行该函数,而不是第一次,它会进入内部。
这是应用程序:
Jsfiddle 如果您输入一个城市名称并单击一次按钮,如果您再次按预期工作时单击该按钮,它只会找到该位置,它会丢弃引脚并创建表格..有人知道为什么吗?谢谢。
【问题讨论】:
标签: javascript html google-places-api