我正在將Google Maps API集成到我正在處理的網站中。大多數情況下,它會按需要執行;但是,在撥打附近的搜索服務時,我很難獲取返回的網址(位置的Google地圖頁面)。根據我對Google文檔的理解,這個調用返回一個帶有各種屬性的PlaceResult對象,包括url.I能夠正確訪問其他兩個屬性,名稱和附近,但是url屬性未定義。這個問題可能是什麼?謝謝。Google Maps JavaScript Places API - URL undefined
相關的代碼片段:
var keyword = document.getElementById("searchBox").value;
var requestOptions = {
location: { lat: 37.3011339, lng: -89.5770238},
radius: '5000',
keyword: keyword
};
placesService = new google.maps.places.PlacesService(hotelMap);
placesService.nearbySearch(requestOptions, findCallback);
});
}; // end initiallize
function findCallback(results, status) {
var resultsList = "";
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
alert(results[i].url); // this returns undefined
resultsList += "<li>" + results[i].name + ": " + results[i].vicinity + " - <a href='" + results[i].url + "'>View Details</a></li>";
}
document.getElementById("searchList").innerHTML = resultsList;
}
}
參考:
https://developers.google.com/maps/documentation/javascript/reference#PlaceResult
測試在更多的地方?你正在看的地方可能實際上並沒有谷歌網頁?或者,使用網站對象,只顯示可用。 –