2

我想要獲取地圖上顯示的地點的更多信息,例如地址,電話號碼等。您可以在此處看到我的代碼:Google Places API - 獲取地址,電話號碼等

http://jsfiddle.net/aboother/4q3jcg1s/

我做了「console_log(地方)」,如下:

function createMarker(place) { 
    var placeLoc = place.geometry.location; 
    var marker = new google.maps.Marker({ 
     map: map, 
     position: place.geometry.location 
    }); 

    console.log(place); 

    var request = { reference: place.reference }; 
    service.getDetails(request, function(details, status) { 
     google.maps.event.addListener(marker, 'click', function() { 
      console.log(place); 
      infowindow.setContent(place.name + "<br />" + place.vicinity); 
      infowindow.open(map, this); 
     }); 
    }); 
} 

,但我看不到,即使我知道你能得到這個信息,這個對象的地址或電話號碼。我只能看到「附近」,「名稱」和其他基本信息。誰能幫忙?

+0

請編輯你的jsfiddle。由於存在資源錯誤,我們無法看到日誌。 –

+0

嘗試是弗拉德:http://jsfiddle.net/aboother/4q3jcg1s/ – aboother

+0

的小提琴作品,找到了解決辦法發佈不久。 –

回答

2

那麼你使用的服務:service.nearbySearch()附近的基於搜索的一些標準。同樣有以下服務:service.getDetails()獲得所有的透視細節。我不完全確定,但從我的理解中,服務使用placeID來匹配並獲取與該位置有關的所有細節。

在問候你的代碼,而不是直接創造了每一個地方的標誌,它傳遞給getDetails()服務,然後創建一個標記。我登錄了這個地方,所有的細節都在那裏,您可以根據需要使用這些數據。

下面是修改後的代碼:

function callback(results, status) { 
    if(status == google.maps.places.PlacesServiceStatus.OK) { 
     for(var i = 0; i < results.length; i++) {    
      service.getDetails(results[i], function(place, status) { 
       if (status == google.maps.places.PlacesServiceStatus.OK) { 
        var marker = new google.maps.Marker({ 
         map: map, 
         position: place.geometry.location 
        }); 
        console.log(place); 
        google.maps.event.addListener(marker, 'click', function() { 
         infowindow.setContent(place.name); 
         infowindow.open(map, this); 
        }); 
       }  
      }); 
     } 
    } 
} 

這裏是小提琴:使用哪種控制檯您用於擴大每個位置,你會看到所有的數據,從電話號碼,給他們的評論:http://jsfiddle.net/r61tqtxw/1/

+1

非常好,那是一種享受。非常感謝! – aboother