Sergey Kuznetsov
Sergey Kuznetsov

Reputation: 285

geocoding google maps api return different place_id

Geocoding: 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

Return

{    "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" }

But I get incorrect result, when I try find place info by place_id from previos results.

For example: Find place by place_id https://maps.googleapis.com/maps/api/place/details/json?placeid=EkbQm9GD0LHRj9C90YHQutC40Lkg0L_RgNC-0LXQt9C0LCAzLCDQnNC-0YHQutCy0LAsINCg0L7RgdGB0LjRjywgMTAxMDAw&key=YOUR_GOOGLE_GEO_API_KEY

Result:

>     {    "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" }

How can you see, the place_id is different in request and response.

In request (last link): EkbQ......AxMDAw

In response: Ej_Qm9.....MDEwMDA

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

The same place have two different place_id.

How can I solve this problemm? I need help!

Upvotes: 1

Views: 3260

Answers (2)

Scott
Scott

Reputation: 3732

To answer your question, there is no problem to solve. As @geocodezip says, a single location may have multiple place ID's. Both of your place IDs are valid and stable and you can use either. There are more details here: https://developers.google.com/places/place-id#multiple-ids

When you request place details for a specific place ID, you receive the details for the requested place. Note however that the place ID may be different, if the place has received a new ID since your previous request. You can safely continue to use the original place ID to access the place, but it's recommended that you swap to using the most recently-returned place ID whenever possible.

Upvotes: 0

geocodezip
geocodezip

Reputation: 161324

The place_id is not unique. The place is unique. There is nothing in the documentation that says there is a one-to-one mapping of place to place_id, only from place_id to place. In fact the documentation specifically states that a place can have multiple place IDs.

From the documentation

Note: Place IDs are also available through the Places API. A single place ID refers to only one place, but a place can have multiple place IDs. For more information, see the place ID overview.

Upvotes: 4

Related Questions