[英]Can I use a formatted address in Google Places API call
I am hoping to provide a specific function in my app.我希望在我的应用程序中提供特定功能。 I want to be able to enter an address, or use an address stored in a database eg "119 Harley Street, London" or "119 Harley Street" (this is just a random address to illustrate my requirements taken from the Google Places 'vicinity' field relating to a business called "The London Clinic Eye Centre").
我希望能够输入一个地址,或使用存储在数据库中的地址,例如“伦敦哈雷街 119 号”或“哈雷街 119 号”(这只是一个随机地址,以说明我从 Google Places 附近的要求' 与名为“伦敦诊所眼科中心”的企业相关的领域)。
Based on the address entered, I would like to be able to identify the Business Name at this address, if there is one, so the 'name' field in the Places JSON result, and also identify if there are any recent reviews by customers, with Date/Time and the review itself, photos etc.根据输入的地址,我希望能够识别此地址的商家名称,如果有,那么 Places JSON 结果中的“名称”字段,并确定是否有客户最近的评论,日期/时间和评论本身,照片等。
Is this at all possible, or am I looking for something that isn't possible?这是可能的,还是我在寻找不可能的东西? I have experience of using other Google APIs (Geolocation & JS) but this is a new one to me, and can't see any way of achieving this from the documentation - I hope I am missing something.
我有使用其他 Google API(地理定位和 JS)的经验,但这对我来说是新的,并且从文档中看不到任何实现这一点的方法 - 我希望我遗漏了一些东西。
Can anyone help?任何人都可以帮忙吗? An alternative way of achieving what I need would also be much appreciated.
实现我需要的另一种方式也将不胜感激。
Many thanks in advance.提前谢谢了。
Looks like you want something like the At this location in Google Maps ( example ):看起来您想要类似于 Google 地图中的此位置( 示例):
This is not exactly available in the same way in the Places API, but I think you can use Nearby Search to get pretty close:这在 Places API 中并不完全可用,但我认为您可以使用Nearby Search来接近:
location
, no keyword
, and rankby=distance
location
、无keyword
和rankby=distance
Example Nearby Search request for "Bahnhofstrasse 30 Zurich", which geocodes to 47.3705904,8.5391694: “Bahnhofstrasse 30 Zurich”的附近搜索请求示例,其地理编码为 47.3705904,8.5391694:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=47.3705904,8.5391694&rankby=distance&key=YOUR_API_KEY https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=47.3705904,8.5391694&rankby=distance&key=YOUR_API_KEY
Results (name, vicinity):结果(名称,附近):
Here is a little snippet straight from Google that show you how to use the "prediction" API to get a list of suggested places:这是直接来自 Google 的一个小片段,向您展示如何使用“预测”API 来获取建议地点的列表:
function initCallback() { var getDetailsCallback = function(place, status) { if (status != google.maps.places.PlacesServiceStatus.OK) { alert(status); return; } // write details of place to console console.log('Place'); console.log(place); }; var getQueryPredictionsCallback = function(predictions, status) { if (status != google.maps.places.PlacesServiceStatus.OK) { alert(status); return; } // write predictions to the console console.log('Predictions'); console.log(predictions); // get details of each prediction var map = new google.maps.Map(document.createElement('div')); var placesService = new google.maps.places.PlacesService(map); predictions.forEach(function(prediction) { placesService.getDetails({ placeId: prediction.place_id }, getDetailsCallback); }); }; var autocompleteService = new google.maps.places.AutocompleteService(); autocompleteService.getQueryPredictions({ input: '119 Harley Street' }, getQueryPredictionsCallback); }
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?&libraries=places&callback=initCallback" async defer></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.