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

Can I use a formatted address in Google Places API call

我希望在我的应用程序中提供特定功能。我希望能够输入地址,或使用存储在数据库中的地址,例如“119 Harley Street, London”或“119 Harley Street”(这只是一个随机地址,用于说明我从与名为 "The London Clinic Eye Centre" 的企业相关的 Google Places 'vicinity' 字段中获取的要求) .

根据输入的地址,我希望能够识别该地址的商家名称(如果有的话),因此地点 JSON 结果中的 'name' 字段,以及还确定是否有客户最近的评论,包括 Date/Time 和评论本身、照片等

这完全有可能吗,还是我正在寻找不可能的东西?我有使用其他 Google API(地理定位和 JS)的经验,但这对我来说是一个新的,并且无法从文档中看到任何实现此目的的方法 - 我希望我遗漏了一些东西。

有人可以帮忙吗?另一种实现我需要的方法也将不胜感激。

非常感谢。

这里有一个直接来自 Google 的小片段,向您展示了如何使用 "prediction" 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>

您似乎想要 Google 地图 (example) 中的 此位置:

这在地方 API 中的使用方式并不完全相同,但我认为您可以使用 Nearby Search 来获得非常接近的效果:

  1. 使用地点自动完成(或地理编码)获取地址(或公司,这无关紧要)的经纬度。
  2. 使用“附近地点搜索”查找该位置的所有机构,查询时使用 locationkeywordrankby=distance
  3. 只保留最接近的结果(前几个)and/or(可能)按地址过滤。

"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

结果(姓名、附近):

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