地理编码谷歌地图api返回不同的place_id

时间:2015-04-20 14:58:18

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

天气预报 http://maps.googleapis.com/maps/api/geocode/json?address=%D0%A0%D0%BE%D1%81%D1%81%D0%B8%D1%8F%2C+%D0%B3%D0%BE%D1%80%D0%BE%D0%B4+%D0%9C%D0%BE%D1%81%D0%BA%D0%B2%D0%B0%2C+%D0%9C%D0%BE%D1%81%D0%BA%D0%B2%D0%B0%2C+%D0%9B%D1%83%D0%B1%D1%8F%D0%BD%D1%81%D0%BA%D0%B8%D0%B9+%D0%BF%D1%80%D0%BE%D0%B5%D0%B7%D0%B4+3&sensor=false

返回

{    "results" : [
  {
     "address_components" : [
        {
           "long_name" : "3",
           "short_name" : "3",
           "types" : [ "street_number" ]
        },
        {
           "long_name" : "Lubyanskiy proyezd",
           "short_name" : "Lubyanskiy pr-d",
           "types" : [ "route" ]
        },
        {
           "long_name" : "Tsentralnyy administrativnyy okrug",
           "short_name" : "Tsentralnyy administrativnyy okrug",
           "types" : [ "sublocality_level_1", "sublocality", "political" ]
        },
        {
           "long_name" : "Moskva",
           "short_name" : "Moskva",
           "types" : [ "locality", "political" ]
        },
        {
           "long_name" : "gorod Moskva",
           "short_name" : "g. Moskva",
           "types" : [ "administrative_area_level_2", "political" ]
        },
        {
           "long_name" : "Moscow",
           "short_name" : "Moscow",
           "types" : [ "administrative_area_level_1", "political" ]
        },
        {
           "long_name" : "Russia",
           "short_name" : "RU",
           "types" : [ "country", "political" ]
        },
        {
           "long_name" : "101000",
           "short_name" : "101000",
           "types" : [ "postal_code" ]
        }
     ],
     "formatted_address" : "Lubyanskiy proyezd, 3, Moskva, Russia, 101000",
     "geometry" : {
        "bounds" : {
           "northeast" : {
              "lat" : 55.7587676,
              "lng" : 37.6290579
           },
           "southwest" : {
              "lat" : 55.7587612,
              "lng" : 37.6290433
           }
        },
        "location" : {
           "lat" : 55.7587676,
           "lng" : 37.6290579
        },
        "location_type" : "RANGE_INTERPOLATED",
        "viewport" : {
           "northeast" : {
              "lat" : 55.76011338029149,
              "lng" : 37.6303995802915
           },
           "southwest" : {
              "lat" : 55.75741541970849,
              "lng" : 37.6277016197085
           }
        }
     },
     "place_id" : "EkbQm9GD0LHRj9C90YHQutC40Lkg0L_RgNC-0LXQt9C0LCAzLCDQnNC-0YHQutCy0LAsINCg0L7RgdGB0LjRjywgMTAxMDAw",
     "types" : [ "street_address" ]
  },
  {
     "address_components" : [
        {
           "long_name" : "3",
           "short_name" : "3",
           "types" : [ "street_number" ]
        },
        {
           "long_name" : "Lubyanskiy proyezd",
           "short_name" : "Lubyanskiy pr-d",
           "types" : [ "route" ]
        },
        {
           "long_name" : "Tsentralnyy administrativnyy okrug",
           "short_name" : "Tsentralnyy administrativnyy okrug",
           "types" : [ "sublocality_level_1", "sublocality", "political" ]
        },
        {
           "long_name" : "Moskva",
           "short_name" : "Moskva",
           "types" : [ "locality", "political" ]
        },
        {
           "long_name" : "gorod Moskva",
           "short_name" : "g. Moskva",
           "types" : [ "administrative_area_level_2", "political" ]
        },
        {
           "long_name" : "Moscow",
           "short_name" : "Moscow",
           "types" : [ "administrative_area_level_1", "political" ]
        },
        {
           "long_name" : "Russia",
           "short_name" : "RU",
           "types" : [ "country", "political" ]
        },
        {
           "long_name" : "109074",
           "short_name" : "109074",
           "types" : [ "postal_code" ]
        }
     ],
     "formatted_address" : "Lubyanskiy proyezd, 3, Moskva, Russia, 109074",
     "geometry" : {
        "bounds" : {
           "northeast" : {
              "lat" : 55.7539059,
              "lng" : 37.6355031
           },
           "southwest" : {
              "lat" : 55.7538962,
              "lng" : 37.6354968
           }
        },
        "location" : {
           "lat" : 55.7539059,
           "lng" : 37.6354968
        },
        "location_type" : "RANGE_INTERPOLATED",
        "viewport" : {
           "northeast" : {
              "lat" : 55.7552500302915,
              "lng" : 37.6368489302915
           },
           "southwest" : {
              "lat" : 55.7525520697085,
              "lng" : 37.6341509697085
           }
        }
     },
     "partial_match" : true,
     "place_id" : "EkbQm9GD0LHRj9C90YHQutC40Lkg0L_RgNC-0LXQt9C0LCAzLCDQnNC-0YHQutCy0LAsINCg0L7RgdGB0LjRjywgMTA5MDc0",
     "types" : [ "street_address" ]
  }    ],    "status" : "OK" }

但是当我尝试通过place_id从previos结果中找到地方信息时,我得到的结果不正确。

例如: 按place_id https://maps.googleapis.com/maps/api/place/details/json?placeid=EkbQm9GD0LHRj9C90YHQutC40Lkg0L_RgNC-0LXQt9C0LCAzLCDQnNC-0YHQutCy0LAsINCg0L7RgdGB0LjRjywgMTAxMDAw&key=YOUR_GOOGLE_GEO_API_KEY

查找地点

结果:

>     {    "html_attributions" : [],    "result" : {
>       "address_components" : [
>          {
>             "long_name" : "3",
>             "short_name" : "3",
>             "types" : [ "street_number" ]
>          },
>          {
>             "long_name" : "Lubyanskiy proyezd",
>             "short_name" : "Lubyanskiy pr-d",
>             "types" : [ "route" ]
>          },
>          {
>             "long_name" : "Tsentralnyy administrativnyy okrug",
>             "short_name" : "Tsentralnyy administrativnyy okrug",
>             "types" : [ "sublocality_level_1", "sublocality", "political" ]
>          },
>          {
>             "long_name" : "Moskva",
>             "short_name" : "Moskva",
>             "types" : [ "locality", "political" ]
>          },
>          {
>             "long_name" : "gorod Moskva",
>             "short_name" : "g. Moskva",
>             "types" : [ "administrative_area_level_2", "political" ]
>          },
>          {
>             "long_name" : "Moscow",
>             "short_name" : "Moscow",
>             "types" : [ "administrative_area_level_1", "political" ]
>          },
>          {
>             "long_name" : "Russia",
>             "short_name" : "RU",
>             "types" : [ "country", "political" ]
>          },
>          {
>             "long_name" : "101000",
>             "short_name" : "101000",
>             "types" : [ "postal_code" ]
>          }
>       ],
>       "adr_address" : "\u003cspan class=\"street-address\"\u003eLubyanskiy proyezd, 3\u003c/span\u003e,
> \u003cspan class=\"locality\"\u003eMoskva\u003c/span\u003e, \u003cspan
> class=\"country-name\"\u003eRussia\u003c/span\u003e, \u003cspan
> class=\"postal-code\"\u003e101000\u003c/span\u003e",
>       "formatted_address" : "Lubyanskiy proyezd, 3, Moskva, Russia, 101000",
>       "geometry" : {
>          "location" : {
>             "lat" : 55.7587676,
>             "lng" : 37.6290579
>          }
>       },
>       "icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
>       "id" : "38efff77618f372a66fe6aaadde36e46a8d9b0a8",
>       "name" : "Lubyanskiy pr-d, 3",
>       "place_id" : "Ej_Qm9GD0LHRj9C90YHQutC40Lkg0L_RgC4sIDMsINCc0L7RgdC60LLQsCwg0KDQvtGB0YHQuNGPLCAxMDEwMDA",
>       "reference" : "CpQBiwAAAA6ClEFYu1E3xM-8kRNGEf0s6sLJTMfqfroDVdaujzEMomzMTJ7HB80Bb8X5JLNrChwXlcFyKs4Hxn1vwgBm4LBfyCgMLty6WewWGKg7MbJb7ZDBhK0kQMRTcbnPGQ7hAG5MNo9t8LIMfDu0kZmsoCosW1MDEHbiXIHC9uygPYplHN6VzNP71rjh8V0AbiaZ9BIQohpY3YsUs0bWEwDUr74NqRoUttzPvs4Mlv_1nLCiPb_yHz5hW5M",
>       "scope" : "GOOGLE",
>       "types" : [ "street_address" ],
>       "url" : "https://maps.google.com/maps/place?q=Lubyanskiy+proyezd,+3,+Moskva,+Russia,+101000&ftid=0x46b54a5c1e406657:0xd25bbb02ec771347",
>       "vicinity" : "Tsentralnyy administrativnyy okrug"    },    "status" : "OK" }

你怎么看,place_id在请求和响应方面有所不同。

  

请求中(最后一个链接):EkbQ ...... AxMDAw

     

作出回应:Ej_Qm9 ..... MDEwMDA

     

EkbQ ...... AxMDAw!= Ej_Qm9 ...... MDEwMDA

同一个地方有两个不同的place_id。

我该如何解决这个问题呢?我需要帮助!

2 个答案:

答案 0 :(得分:4)

place_id不是唯一的。这个地方很独特。文档中没有任何内容表明地方与place_id之间存在一对一的映射,只是从place_id到地方。事实上,文档明确指出一个地方可以有多个地方ID

From the documentation

  

注意:地方ID也可通过Places API获得。单个地点ID仅指一个地方,但一个地方可以有多个地点ID。有关详细信息,请参阅地点ID概述。

答案 1 :(得分:0)

要回答您的问题,无需解决问题。正如@geocodezip所说,单个位置可能有多个地方ID。您的两个地方ID都有效且稳定,您可以使用其中任何一个。这里有更多详细信息:https://developers.google.com/places/place-id#multiple-ids

  

当您请求特定地点ID的地点详细信息时,您会收到   请求地点的详细信息。但请注意地点ID   可能会有所不同,如果该地方已收到一个新的ID,因为你的   先前的请求。您可以放心地继续使用原始地点ID   访问该地方,但建议你交换使用   最近返回的地点ID。