简体   繁体   English

获取特定纬度+经度或街道地址的Placeid

[英]Get placeid for specific Latitude + Longitude or street address

In Excel, I have both Street Address and Lat+Long and trying to get the PlaceID from Google Places API Web Service. 在Excel中,我同时拥有Street Address和Lat + Long,并尝试从Google Places API Web服务获取PlaceID。 I research Geocoding API and Places API and did some VBA testing. 我研究了Geocoding API和Places API,并进行了一些VBA测试。 The only way to get PlaceID for specific place is to do Text Search or Nearby Search. 获取特定地点的PlaceID的唯一方法是进行文本搜索或附近搜索。

Is there a way to get it from the address you have directly in VBA? 有没有办法从您直接在VBA中获得的地址获取它? I've seen a demo website that using JavaScript to obtain the PlaceID, but don't know how to incorporate the JavaScript into Excel+VBA. 我看过一个演示网站,该网站使用JavaScript获取PlaceID,但不知道如何将JavaScript集成到Excel + VBA中。

Sound like you want NearbySearch (not sure why you don't think that gives you what you want): 听起来像是您想要NearestSearch (不确定为什么您不认为这不能满足您的需求):

A Nearby Search lets you search for places within a specified area by keyword or type. 邻近搜索可让您按关键字或类型搜索指定区域内的地点。 A Nearby Search must always include a location, which can be specified in one of two ways: 邻近搜索必须始终包含位置,可以通过以下两种方式之一指定位置:

  • a LatLngBounds. LatLngBounds。
  • a circular area defined as the combination of the location property — specifying the center of the circle as a LatLng object — and a radius, measured in meters. 定义为location属性(将圆心指定为LatLng对象)和半径(以米为单位)的组合的圆形区域。

A Places Nearby search is initiated with a call to the PlacesService's nearbySearch() method, which will return an array of PlaceResult objects. 通过调用PlacesService的附近的Search()方法来启动“附近的地方”搜索,该方法将返回PlaceResult对象的数组。

fiddle 小提琴

code snippet: 代码段:

 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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM