获取半径为 100 公里且地点 ID 为 google 个地点的城市

Get Cities around 100 KM radius with place id of google places

我有印度安得拉邦维杰亚瓦达市的地点 ID。它的位置 ID 是 ChIJS5QtSPnvNToRZQJKq4R-m5M

现在使用google个地点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);       
        });     
   }

使用 PlaceDetails 响应return来自此

  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);

return值placeResults是一个地点数组,每个地点都有placeIds