3

与大多数位置查询工作相反,我实际上是在尝试通过其地址或 Google 使用 Google API 来识别企业名称placeid。例如,当我在 googlemaps.com 上搜索时 1625 Wilshire Blvd, Los Angeles, CA 90017,它的结果显示“在这个位置”是“麦当劳”。

但是,当使用以下 URL 进行 API 调用时,名称显示为街道地址,而我想要识别该位置的企业名称(“麦当劳”):

https://maps.googleapis.com/maps/api/place/textsearch/json?query=1625%20Wilshire%20Blvd,%20Los%20Angeles,%20CA%2090017&sensor=false&key=<api_key>

编辑:使用@xomena 推荐的确切调用,我仍然遇到同样的问题。我已经同时运行了 R 和 Python,我得到的结果是街道地址代替了两种方式的名称。

代码

packages <- c("RJSONIO")
new_packages <- packages[!(packages %in% installed.packages()[,"Package"])]
if(length(new_packages)) install.packages(new_packages)

library(RJSONIO)

fromJSON(URLencode(paste("https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=1625%20Wilshire%20Blvd%2C%20Los%20Angeles%2C%20CA%2090017&inputtype=textquery&fields=formatted_address,name,place_id&key=", api_key, sep = "")))

输出

$candidates
$candidates[[1]]
                               formatted_address 
"1625 Wilshire Blvd, Los Angeles, CA 90017, USA" 
                                            name 
                            "1625 Wilshire Blvd" 
                                        place_id 
                   "ChIJ18AW_aPHwoARXRm-cgcRcDs" 


$debug_log
$debug_log$line
list()


$status
[1] "OK"

蟒蛇代码

import requests

requests.get("https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=1625%20Wilshire%20Blvd%2C%20Los%20Angeles%2C%20CA%2090017&inputtype=textquery&fields=formatted_address,name,place_id&key="+API_KEY).json()

蟒蛇输出

{'candidates': [{'formatted_address': '1625 Wilshire Blvd, Los Angeles, CA 90017, USA', 'name': '1625 Wilshire Blvd', 'place_id': 'ChIJ18AW_aPHwoARXRm-cgcRcDs'}], 'debug_log': {'line': []}, 'status': 'OK'}

4

2 回答 2

3

也许您可以使用 Google Place Autocomplete 请求获取商家名称:

https://maps.googleapis.com/maps/api/place/autocomplete/json?input=601%20East%20Kennedy%20Blvd,%20Tampa,%20FL,%20USA&types=establishment&language=en&key=YOUR_API_KEY

我得到以下回复:

{"predictions":[
  {
     "description" : "Quest Diagnostics Inside New Castle Walmart Store, 117 Wilton Blvd, New Castle, DE 19720, USA",
     "id" : "8295289e301fd05ae69a8d3cd8d25da31c29c66d",
     "matched_substrings" : [
        {
           "length" : 10,
           "offset" : 25
        },
        {
           "length" : 11,
           "offset" : 55
        },
        {
           "length" : 2,
           "offset" : 80
        },
        {
           "length" : 5,
           "offset" : 83
        },
        {
           "length" : 3,
           "offset" : 90
        }
     ],
     "place_id" : "ChIJtTv6_PsHx4kRYZZtvcrallQ",
     "reference" : "ChIJtTv6_PsHx4kRYZZtvcrallQ",
     "structured_formatting" : {
        "main_text" : "Quest Diagnostics Inside New Castle Walmart Store",
        "main_text_matched_substrings" : [
           {
              "length" : 10,
              "offset" : 25
           }
        ],
        "secondary_text" : "117 Wilton Blvd, New Castle, DE 19720, USA",
        "secondary_text_matched_substrings" : [
           {
              "length" : 11,
              "offset" : 4
           },
           {
              "length" : 2,
              "offset" : 29
           },
           {
              "length" : 5,
              "offset" : 32
           },
           {
              "length" : 3,
              "offset" : 39
           }
        ]
     },
     "terms" : [
        {
           "offset" : 0,
           "value" : "Quest Diagnostics Inside New Castle Walmart Store"
        },
        {
           "offset" : 51,
           "value" : "117 Wilton Blvd"
        },
        {
           "offset" : 68,
           "value" : "New Castle"
        },
        {
           "offset" : 80,
           "value" : "DE"
        },
        {
           "offset" : 83,
           "value" : "19720"
        },
        {
           "offset" : 90,
           "value" : "USA"
        }
     ],
     "types" : [ "health", "point_of_interest", "establishment" ]
  }],"status" : "OK"}

我认为 predictions[0].description 有business name

但不是每次都返回响应。响应的预测可能是一个空数组。

于 2020-06-28T09:39:15.633 回答
2

我相信Find place端点正在做你正在寻找的东西

当我执行以下请求时

https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=1625%20Wilshire%20Blvd%2C%20Los%20Angeles%2C%20CA%2090017&inputtype=textquery&fields=formatted_address,name,place_id&key=MY_API_KEY

我得到以下回复

{
  "candidates":[
    {
      "formatted_address":"1625 Wilshire Blvd, Los Angeles, CA 90017, USA",
      "name":"McDonald's",
      "place_id":"ChIJ0QBm-6PHwoARpfbcollvKIc"
    }
  ],
  "debug_log":{
    "line":[
    ]
  },
  "status":"OK"
}

如您所见,Find place 返回了麦当劳的业务。

我希望这有帮助!

更新

有趣的。您是否偶然知道您的服务器在哪里?正如您在文档中看到的,默认情况下查找位置使用 IP 地址偏差。我的服务器位于美国,我买的是麦当劳,如果您的服务器 IP 地址来自不同的地区,由于位置偏差,您可能会得到不同的结果。在这种情况下,我可以建议指定一个区域来偏向您的结果,例如定义圆形或矩形区域。请求应该类似于

https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=1625%20Wilshire%20Blvd%2C%20Los%20Angeles%2C%20CA%2090017&inputtype=textquery&fields=formatted_address,geometry,name,place_id&locationbias=circle%3A100%4034.0559572%2C-118.2708558&key=YOUR_API_KEY

于 2018-09-17T22:11:09.107 回答