【发布时间】:2012-04-17 10:11:48
【问题描述】:
我一直在寻找一种方法来允许用户手动覆盖网站上的地理位置(以防它不正确)。
感谢任何抽出时间回复我的帖子的人已经在谷歌上搜索了分配但没有任何进展。
【问题讨论】:
标签: php jquery mysql geolocation geo
我一直在寻找一种方法来允许用户手动覆盖网站上的地理位置(以防它不正确)。
感谢任何抽出时间回复我的帖子的人已经在谷歌上搜索了分配但没有任何进展。
【问题讨论】:
标签: php jquery mysql geolocation geo
添加一个文本框供用户输入他们的位置。然后将其提交给地理编码 API 服务,例如 Google Maps、geocoding.us、Yahoo Maps 等。返回并在您的应用程序中使用该结果。
如果您使用 Google Maps API,则对地址进行地理编码非常简单。 address 是用户输入街道地址的文本字段。 latlng 是一个文本字段,用于保存输出的纬度/经度。
$('#searchButton').click(function() {
var geocoder = new google.maps.Geocoder();
geocoder.geocode( {'address': $('#address').val() }, function(data, status) {
if (status == google.maps.GeocoderStatus.OK) {
$('#latlng').val(data[0].geometry.location.lat+", "+data[0].geometry.location.lng);
else {
alert("Geocode was not successful for the following reason: " + status);
}
});
return false;
});
见https://google-developers.appspot.com/maps/documentation/javascript/examples/geocoding-simple
【讨论】: