简体   繁体   English

我可以在 Google Places API 调用中使用格式化的地址吗

[英]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来接近:

  1. Use Places Autocomplete (or Geocoding) to obtain the latlng for an address (or business, it doesn't matter).使用地点自动完成(或地理编码)获取地址(或企业,无关紧要)的纬度。
  2. Use Places Nearby Search to find all establishments at that location, by querying with that latlng as location , no keyword , and rankby=distance使用 Places Nearby Search 查找该位置的所有场所,方法是使用该 latlng 作为location 、无keywordrankby=distance
  3. Keep only the closest results (first few) and/or (maybe) filter by their address.仅保留最接近的结果(前几个)和/或(可能)按地址过滤。

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):结果(名称,附近):

  1. Griederbar, Bahnhofstrasse 30, Zürich Griederbar, Bahnhofstrasse 30, 苏黎世
  2. Coiffure Valentino, Bahnhofstrasse 30, Zürich Coiffure Valentino, Bahnhofstrasse 30, Zürich
  3. Grieder G.Point, Bahnhofstrasse 30, Zürich Grieder G.Point, Bahnhofstrasse 30, Zürich
  4. Shanty Beauty Design, Bahnhofstrasse 30, Zürich棚户区美容设计,班霍夫大街 30 号,苏黎世
  5. Louis Vuitton, Bahnhofstrasse 30, Zürich路易威登,班霍夫大街 30 号,苏黎世
  6. Brunschwig & Cie Sa, Bahnhofstrasse 30, Zürich Brunschwig & Cie Sa, Bahnhofstrasse 30, Zürich
  7. Clariden Leu, Bahnhofstrasse 32 , Zürich Clariden Leu, Bahnhofstrasse 32 , 苏黎世
  8. Gen Del Sa, Bahnhofstrasse 32 , Zürich Gen Del Sa, Bahnhofstrasse 32 , 苏黎世
  9. Abegg & Co AG, Zürich, Bahnhofstrasse 30, Zürich Abegg & Co AG, Zürich, Bahnhofstrasse 30, Zürich
  10. Wohlfahrtsfonds der Clariden Leu AG, Bahnhofstrasse 32 , Zürich Wohlfahrtsfonds der Clariden Leu AG, Bahnhofstrasse 32 , Zürich
  11. Uhren shop Zürich Jaeger-LeCoultre, Bahnhofstrasse 32 , Zürich Uhren shop Zürich Jaeger-LeCoultre, Bahnhofstrasse 32 , Zürich
  12. TOD'S Boutique, Bahnhofstrasse 32 , Zürich TOD'S 精品店,班霍夫大街32 号,苏黎世
  13. Audemars Piguet, Boutique Zurich, Bahnhofstrasse 32 , Zürich Audemars Piguet, Boutique Zurich, Bahnhofstrasse 32 , Zürich
  14. Grieder, Bahnhofstrasse 30, Zürich Grieder, Bahnhofstrasse 30, 苏黎世
  15. ─ 20. no more results at Bahnhofstrasse 30, Zürich ─ 20. Bahnhofstrasse 30, Zürich 没有更多结果

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.

相关问题 我可以通过 react-google-maps/api 使用 Google 地方信息吗? - Can I use Google Places with react-google-maps/api? 在某些地方,“ formatted_address”为null,但在某些地方不是全部(Google Maps API),为什么呢? - 'formatted_address' is null for some places, but not all ( Google Maps API ) Why is this? 更改由Google Places API自动完成方法调用的formatted_address的语言 - Changing the language of the formatted_address called by google Places API autocomplete method 与Google Places API的address_component相比,我如何命名HTML输入ID? - How can I name the HTML input ID differently than than the address_component for Google Places API? Google地方信息-无需用户输入即可获取格式化的地址 - Google Places - Get formatted address without user input 如何将 React 与 Google Places API 结合使用,以在 Google 地图上显示地点标记? - How can I use React with Google Places API, to display place markers on a Google map? Google Maps API formatted_address - Google Maps API formatted_address Google Places API-地址和电话号码? - Google Places API- Address and phone number? Google Places API - 使用该城市查找地址 - Google Places API - find an address using the city Google API 地点 - 地址建议来自城市 - Google API Places - Address suggest from a city
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM