簡體   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