[英]nearby places in google maps api
我必須開發一個網站,用戶可以在其中輸入特定位置的緯度和經度。 基於緯度和經度,我應該獲取附近的位置並將其顯示在谷歌地圖上。 截至目前,我顯示了一種類型的附近位置,例如.restaurants,現在我想使用 place-API 獲取不止一種類型。
不幸的是,現在既不能使用多種類型進行搜索,也不能從查詢中排除一種類型。 Google 的政策只是強迫人們發送更多請求。 有時人們會為他們不想要的東西付費,或者為他們只用一個查詢就可以實現的東西付費。
雖然沒有第二、第三個參數的搜索選項,但您仍然可以獲得您想要的東西,當然需要為此付費。
這是常規 NearbySearch 請求的樣子;
var service = new google.maps.places.PlacesService(map);
let latLng = new google.maps.LatLng(latitude,longitude);
service.nearbySearch(
{location: latLng, radius: 500, type: ['store']},
function(results, status) {
if (status !== 'OK') return;
// results
};
});
如果你想獲得多種類型,你必須為每個類型發送一個請求,看起來像這樣;
var service = new google.maps.places.PlacesService(map);
let latLng = new google.maps.LatLng(latitude,longitude);
service.nearbySearch(
{location: latLng, radius: 500, type: ['store']},
function(results, status) {
if (status !== 'OK') return;
// results for store
service.nearbySearch(
{location:latLng, radius: 1500, type : ['fire_station']},
function(fireStationResult, fireStationStatus) {
// firestation results here
// and so on.
}
)
};
});
您必須在彼此的塊中使用 nearSearch 請求,因為它是異步工作的。
Places API 的Nearby Search目前不支持搜索多種類型。
有一個現有的功能請求: https : //issuetracker.google.com/issues/112291747 。 我建議你在那里評論你的用例並給它加星號以接收更新。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.