简体   繁体   English

反向地理编码 - Google Maps v3

[英]Reverse Geocoding - Google Maps v3

To start, I'm not very good at programming and am just a beginner so please keep that in mind with any responses. 首先,我不是很擅长编程,而且只是一个初学者,所以请记住任何回复。 My problem is with reverse geocoding using Google Maps v3. 我的问题是使用Google Maps v3进行反向地理编码。 I have found plenty of examples on the internet and have gotten the basics of my map working, however the reverse geocoding part is frustrating me in that I simply cannot get it to work. 我在互联网上找到了很多例子,并且已经掌握了我的地图工作的基础知识,但反向地理编码部分令我感到沮丧,因为我无法让它工作。 I keep on getting an error of "object HTMLDivElement". 我继续收到“对象HTMLDivElement”的错误。 The part of the code that I am having trouble with is: 我遇到问题的代码部分是:

  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)

The map still loads, yet the infobox reads "38.41065600530499, -112.8515374999995; Closest Matching Address:["object HTMLDivElement"] 地图仍然加载,但信息框显示“38.41065600530499,-112.8515374999995;最近的匹配地址:[”对象HTMLDivElement“]

So what is it that I need to change? 那么我需要改变什么呢? I'm certain that the code listed above has something wrong with it, but what exactly? 我确定上面列出的代码有问题,但具体到底是什么?

Thanks for any and all help. 感谢您的帮助。

The geocoder is asynchronous. 地理编码器是异步的。 You must be testing in IE and have a div with id="address". 您必须在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