我有一个城市Vijayawada,Andhra Prades,印度的id。它的位置是ChIJS5QtSPnvNToRZQJKq4R-m5M
现在使用google places api,我们如何在100KM范围内获取城市及其地方ID。
function initialize() {
var options = {
types: ['(cities)'],
componentRestrictions: {country: "in"}
};
var input = document.getElementById('location_city');
var autocomplete = new google.maps.places.Autocomplete(input, options);
google.maps.event.addListener(autocomplete, 'place_changed', function() {
var place = autocomplete.getPlace();
console.log("Place ID is " + place.place_id);
});
}
答案 0 :(得分:2)
使用从此
返回的PlaceDetails响应 json = $http.get('https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJS5QtSPnvNToRZQJKq4R-m5M&key=YOUR_API_KEY')
找到位置属性
var lng = json.result.geometry.location.lat
var lng = json.result.geometry.location.lng
然后应在KM
中输入半径 var service = new google.maps.places.PlacesService(map);
var pyrmont = {lat: lat, lng: lng};
placeResults = service.nearbySearch({
location: pyrmont,
radius: 1000 // meters
}, callback);
返回值placeResults
是一个地方数组,每个地方都有placeIds