繁体   English   中英

反向地理编码 - Google Maps v3

[英]Reverse Geocoding - Google Maps v3

首先,我不是很擅长编程,而且只是一个初学者,所以请记住任何回复。 我的问题是使用Google Maps v3进行反向地理编码。 我在互联网上找到了很多例子,并且已经掌握了我的地图工作的基础知识,但反向地理编码部分令我感到沮丧,因为我无法让它工作。 我继续收到“对象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)

地图仍然加载,但信息框显示“38.41065600530499,-112.8515374999995;最近的匹配地址:[”对象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)
    }
  });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM