javascript - 反向地理编码 - Google map v3

标签 javascript html google-maps

首先,我不是很擅长编程,只是一个初学者,所以请在回复时记住这一点。 我的问题是使用 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/

相关文章:

html - CSS:为什么我的图像没有被渲染?

javascript - 谷歌地图回调后Angular2双向绑定(bind)停止工作

android - 如果 GPS 被禁用,定位无法进入三星手机

javascript - 如何在 Closure Compiler 的 javascript 中注释嵌套对象并使所有属性都是可选的?

javascript - 从另一个下拉列表中选择一个值后填充下拉列表

jquery - 显示无在 jQuery 按钮单击中添加新行

javascript - 如何使用 Swift 加载 javascript 后获取页面的 HTML 源代码

javascript - 将获取远程链接加载到引导模式框中

php - 如何通过 Javascript 将 php session 从一个页面转移到另一个页面?

JavaScript 在 FF 和 IE 中不起作用