![](/img/trans.png)
[英]How do I retrieve place details from the Google Places JS API using a place ID?
[英]How to get all place details from a Place Details Request using Google Places API Web Service?
我正在嘗試使用Google Places API網絡服務從“地點詳細信息請求”中獲取數據,例如電話號碼。 即使我從相同的地址獲取位置ID,也無法獲得與本指南中顯示的響應數據相似的響應數據。
我得到的地點編號與指南中的地點編號不同。 我的地方ID是“ ChIJ8UadyjeuEmsRDt5QbiDg720”,而他們的地方是“ ChIJN1t_tDeuEmsRUsoyG83frY4”。 如果使用他們的位置ID,我將獲得所需的所有數據。
我唯一可以獲得的數據是:address_components,adr_address,formatted_address,幾何圖形,圖標,ID,名稱,place_id,引用,范圍,類型,URL和附近。 如何從請求中獲取數據,例如電話號碼?
var placesRequest = $http({
method: "post",
url: "https://maps.googleapis.com/maps/api/place/details/json?placeid=" + <my place id>+"&key=<my key>"
});
placesRequest.success(function (data) {
console.log("data", data);
});
使用此代碼的Google Maps JavaScript API同樣存在問題。
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -33.866, lng: 151.196},
zoom: 15
});
google.maps.InfoWindow();
var service = new google.maps.places.PlacesService(map);
service.getDetails({
placeId: $scope.newUserData.address.place_id
}, function(place, status) {
if (status === google.maps.places.PlacesServiceStatus.OK) {
if(place) {
console.log("place", place);
}
}
});
}
initMap();
Google Places API中缺少電話號碼,因為Google Maps沒有該特定地方的電話號碼。 如果您在Google地圖上索取帶有電話號碼的地點的詳細信息,則會返回該地點。
仔細看看ChIJ8UadyjeuEmsRDt5QbiDg720。 這是一棟名為“ Workplace 6”的辦公大樓,請注意,細節表明它是premise
類型的。 如果您在url
字段( https://maps.google.com/?q=Workplace+6&ftid=0x6b12ae37ca9d46f1:0x6defe0206e50de0e )中訪問Google Maps URL,您會發現那里也沒有電話號碼。
另一個位置ID ChIJN1t_tDeuEmsRUsoyG83frY4,用於位於該建築物內的一家商家(Google)。 如果比較address_components
或formatted_address
您會發現它們的地址不完全相同(Google的地址是該建築物的5樓)。
通常,一個地方的任何字段都可能不存在。 如果Google Maps不知道,或者根本不適用(例如,您在法國找不到opening_hours
),就會發生這種情況。 正如地點詳情結果的文檔所述:
每個結果可能包含以下字段:
[強調我的]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.