【问题标题】:Get Google Places ID from coordinates从坐标中获取 Google Places ID
【发布时间】:2017-06-02 21:57:00
【问题描述】:

我正在寻找一种从 Google 网络请求中找到 PlaceID 的方法。我有数百个地址(即坐标),我想找到一种方法将它们全部输入phpscript。

我正在为地点 API 的 API 请求而苦苦挣扎。我有以下要求:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=50.096332,8.673130&radius=1&key=APIKEY

这将返回整个法兰克福市,但这不是我想要的。如果我在PlaceID finder on the Google Maps documentation site 中输入地址Oskar-Sommer-Strasse 7, Frankfurt am Main, Deutschland,则会得到ID ChIJ-b9GgAUMvUcRYuYKJtGGlw4 的以下结果。

我现在正在寻找一种方法来完成这项工作。我也使用 Google Maps API 收集了坐标,所以它们应该匹配(或者至少我是这么认为的)。

也许我需要使用其他请求类型?

【问题讨论】:

    标签: php google-maps google-maps-api-3 google-places-api


    【解决方案1】:

    使用地理编码API并向

    发送请求

    https://maps.googleapis.com/maps/api/geocode/json?address=Oskar-Sommer-Strasse+7+%20Frankfurt%20am%20Main%20&component=Deutschland

    返回(我假设您想要地点 id 字段)

     {
       "results" : [
          {
             "address_components" : [
                {
                   "long_name" : "7",
                   "short_name" : "7",
                   "types" : [ "street_number" ]
                },
                {
                   "long_name" : "Oskar-Sommer-Straße",
                   "short_name" : "Oskar-Sommer-Straße",
                   "types" : [ "route" ]
                },
                {
                   "long_name" : "Frankfurt am Main Süd",
                   "short_name" : "Frankfurt am Main Süd",
                   "types" : [ "political", "sublocality", "sublocality_level_1" ]
                },
                {
                   "long_name" : "Frankfurt am Main",
                   "short_name" : "Frankfurt am Main",
                   "types" : [ "locality", "political" ]
                },
                {
                   "long_name" : "Darmstadt",
                   "short_name" : "DA",
                   "types" : [ "administrative_area_level_2", "political" ]
                },
                {
                   "long_name" : "Hessen",
                   "short_name" : "HE",
                   "types" : [ "administrative_area_level_1", "political" ]
                },
                {
                   "long_name" : "Germany",
                   "short_name" : "DE",
                   "types" : [ "country", "political" ]
                },
                {
                   "long_name" : "60596",
                   "short_name" : "60596",
                   "types" : [ "postal_code" ]
                }
             ],
             "formatted_address" : "Oskar-Sommer-Straße 7, 60596 Frankfurt am Main, Germany",
             "geometry" : {
                "location" : {
                   "lat" : 50.09665,
                   "lng" : 8.67299
                },
                "location_type" : "ROOFTOP",
                "viewport" : {
                   "northeast" : {
                      "lat" : 50.0979989802915,
                      "lng" : 8.674338980291502
                   },
                   "southwest" : {
                      "lat" : 50.0953010197085,
                      "lng" : 8.671641019708497
                   }
                }
             },
             "place_id" : "ChIJ-b9GgAUMvUcRYuYKJtGGlw4",
             "types" : [ "street_address" ]
          }
       ],
       "status" : "OK"
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-21
      • 2013-02-03
      • 1970-01-01
      • 2021-12-03
      • 1970-01-01
      相关资源
      最近更新 更多