【发布时间】:2015-10-27 22:56:12
【问题描述】:
我正在尝试在 javascript 中使用 Google Maps Geocoding API。我有以下代码:
var geocoder = new google.maps.Geocoder();
function geocodeAddress() {
var address = document.getElementById("address").value;
geocoder.geocode({"address": address}, function(results, status) {
if (status === google.maps.GeocoderStatus.OK) {
alert(JSON.stringify(results[0].geometry))
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
我得到正确地址的结果是:
{"location":{},"location_type":"ROOFTOP","viewport":{"O":{"O":52.2080810197085,"j":52.2107789802915},"j":{"j":21.018444019708568,"O":21.02114198029153}}}
如您所见,它没有正确设置位置。有什么建议吗?
【问题讨论】:
-
你打算用坐标做什么?您可以使用记录在案的
.lat()和.lng()方法从 google.maps.LatLng 对象中获取它们。
标签: javascript google-maps geocoding google-geocoding-api