【发布时间】:2018-02-12 18:06:19
【问题描述】:
我正在使用 Google Places API,我想知道是否可以只返回一个最接近的结果。在下面的示例中,我可以返回 1 公里半径内的所有健身房,这很好,但如果我要返回最近的警察局或医院,我只想知道最近的有没有办法做到这一点.似乎 API 正在返回半径内的所有对象,并且无法更改。我似乎找不到任何突出显示此问题的文档,并且我所做的任何尝试仍然返回该区域的所有位置。
function GymReport(){
// Gets the latitude and longitude of a location searched by a user
$('.search_latitude').val(marker.getPosition().lat());
$('.search_longitude').val(marker.getPosition().lng());
var Lat = marker.getPosition().lat();
console.log(Lat);
var Long = marker.getPosition().lng();
console.log(Long);
var location = {lat: Lat, lng: Long};
var service = new google.maps.places.PlacesService(map);
service.nearbySearch({
location: location,
radius: 1000,
type: ['gym']
}, callback);
}
回调类
function callback(results, status) {
if (status === google.maps.places.PlacesServiceStatus.OK) {
if(marker)
marker.setMap(null)
for (var i = 0; i < results.length; i++) {
createMarker(results[i]);<-- This calls the function that will create the markers for the array of results from the API.
}
}
}
【问题讨论】:
标签: javascript google-maps google-maps-api-3 google-places-api