【问题标题】:Get placeid for specific Latitude + Longitude or street address获取特定纬度 + 经度或街道地址的 placeid
【发布时间】:2015-05-23 18:21:30
【问题描述】:

在 Excel 中,我有 Street Address 和 Lat+Long,并试图从 Google Places API Web Service 获取 PlaceID。我研究了 Geocoding API 和 Places API 并做了一些 VBA 测试。获取特定地点的 PlaceID 的唯一方法是进行文本搜索或附近搜索。

有没有办法从您在 VBA 中直接拥有的地址获取它? 我看过一个演示网站,使用JavaScript获取PlaceID,但不知道如何将JavaScript合并到Excel+VBA中。

【问题讨论】:

标签: vba google-maps excel google-places-api


【解决方案1】:

听起来像你想要的NearbySearch(不知道为什么你不认为这给了你想要的东西):

“附近搜索”可让您按关键字或类型搜索指定区域内的地点。附近搜索必须始终包含一个位置,可以通过以下两种方式之一指定:

  • LatLngBounds。
  • 定义为位置属性(将圆心指定为 LatLng 对象)和半径(以米为单位)的组合的圆形区域。

Places Nearby 搜索通过调用 PlacesService 的 nearSearch() 方法启动,该方法将返回 PlaceResult 对象数组。

fiddle

代码sn-p:

var map;
var infowindow;

function initialize() {
  var pyrmont = new google.maps.LatLng(-33.8665433, 151.1956316);

  map = new google.maps.Map(document.getElementById('map-canvas'), {
    center: {lat:40.689249,lng:-74.0445},
    zoom: 15
  });

  var request = {
      location: {lat:40.689249,lng:-74.0445},
    radius: 10
  };
  infowindow = new google.maps.InfoWindow();
  var service = new google.maps.places.PlacesService(map);
  service.nearbySearch(request, callback);
}

function callback(results, status) {
  if (status == google.maps.places.PlacesServiceStatus.OK) {
    for (var i = 0; i < results.length; i++) {
      createMarker(results[i]);
    }
  }
}

function createMarker(place) {
  var placeLoc = place.geometry.location;
  var marker = new google.maps.Marker({
    map: map,
    position: place.geometry.location
  });

  google.maps.event.addListener(marker, 'click', function() {
    infowindow.setContent(place.name+"<br>"+place.place_id);
    infowindow.open(map, this);
      document.getElementById('placeId').innerHTML = place.name+"<br>"+marker.getPosition().toUrlValue(6)+"<br>"+place.place_id;
  });
}

google.maps.event.addDomListener(window, 'load', initialize);
html, body, #map-canvas {
    height: 500px;
    width: 500px;
    margin: 0px;
    padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js?libraries=places"></script>
<div id="placeId"></div>
<div id="map-canvas" style="border: 2px solid #3872ac;"></div>

【讨论】:

    猜你喜欢
    • 2010-09-14
    • 2018-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-06
    • 1970-01-01
    • 2014-09-04
    相关资源
    最近更新 更多