首先,我不是很擅长编程,只是一个初学者,所以请在回复时记住这一点。 我的问题是使用 Google Maps v3 进行反向地理编码。我在 Internet 上找到了很多示例,并且已经了解了我的 map 工作的基础知识,但是反向地理编码部分让我感到沮丧,因为我根本无法让它工作。我一直收到“object HTMLDivElement”的错误。我遇到问题的代码部分是:
var geocoder = new google.maps.Geocoder();
var point = new google.maps.LatLng(38.41054600530499, -112.85153749999995);
geocoder.geocode({ 'latLng': point }, function (results, status) {
if (status !== google.maps.GeocoderStatus.OK) {
alert(status);
}
// This is checking to see if the Geoeode Status is OK before proceeding
if (status == google.maps.GeocoderStatus.OK) {
console.log(results);
var address = (results[0].formatted_address);
}}
)
var marker = createMarker(point,"Marker 1", point + "<br> Closest Matching Address:" + address)
map 仍在加载,但信息框显示为“38.41065600530499,-112.8515374999995;最接近的匹配地址:["object HTMLDivElement"]
那么我需要改变什么?我确定上面列出的代码有问题,但究竟是什么问题?
感谢所有帮助。
最佳答案
地理编码器是异步的。您必须在 IE 中进行测试并且有一个带有 id="address"的 div。
var geocoder = new google.maps.Geocoder();
var point = new google.maps.LatLng(38.41054600530499, -112.85153749999995);
geocoder.geocode({ 'latLng': point }, function (results, status) {
if (status !== google.maps.GeocoderStatus.OK) {
alert(status);
}
// This is checking to see if the Geoeode Status is OK before proceeding
if (status == google.maps.GeocoderStatus.OK) {
console.log(results);
var address = (results[0].formatted_address);
// create the Marker where the address variable is valid
var marker = createMarker(point,"Marker 1", point + "<br> Closest Matching Address:" + address)
}
});
关于javascript - 反向地理编码 - Google map v3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19410395/