【发布时间】:2014-03-17 17:59:40
【问题描述】:
我有一个网站,它根据表单中的用户输入加载数据。我还想根据相同的输入刷新谷歌地图。不幸的是,当我提交表单时,它通过 SQL 查询正确检索数据,但刷新页面导致谷歌地图重置为原始起点。解决此问题的最佳方法是什么?
表格代码如下:
<form id="user-location" method="post" action="#" onsubmit="return codeAddress();">
<input id="addressInput" name="addressInput" type="text" maxlength="5">
<input id="submit4" value="GO" type="submit" >
</div>
</form>
这是谷歌地图脚本的一部分:
function codeAddress() {
var address = document.getElementById('addressInput').value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
【问题讨论】:
标签: javascript php forms google-maps