Reputation: 4197
When I perform a Google Places Autocomplete request for "98 Spru" I get a Place prediction with one id (013ae3e513081ff1bc9e3dc202df54ba9d147285) and one set of types ("route" and "geocode") but when I fetch for the details of that Place it has a different id (5e66bbb5a5a7eaedd07fabc199e87570bcc0eae6) and a different set of types ("street_address")? The rest of the information is correct. Snippets of requests / responses below.
Is this expected and if so why?
On the client side I'm trying to filter out Autocomplete predictions that are not of some specific type (e.g. "street_address"). This doesn't work since the "types" field in the Autocomplete response doesn't consistently match the "true" types value as returned in the Details response.
Thanks!
Autocomplete Request / Response for "98 Spru" https://maps.googleapis.com/maps/api/place/autocomplete/json?input=98%20Spru&sensor=true&key=MYKEY&location=42.350000,-71.160000&radius=100.000000&types=geocode
{
"description" : "98 Spruce Street, Watertown, MA, United States",
"id" : "013ae3e513081ff1bc9e3dc202df54ba9d147285",
"matched_substrings" : [
{
"length" : 7,
"offset" : 0
}
],
"reference" : "CmRcAAAArJjcgqYuczq9wKmQG0lwv6j_uCBYCrWzS_U76FvnV3fCnWq0_pPf-nu6M9eTYQEpYt4XahA3Vg0GSzMcR23k3Mkxp9sv73ObGmeHDcanEnZ0dWpl69t7eSwmzLbrREQfEhA0CrWTEXtfQhcnfNWnqTukGhQFWBj_lPkoAwG-ZvUIv0GZhgAscQ",
"terms" : [
{
"offset" : 0,
"value" : "98 Spruce Street"
},
{
"offset" : 18,
"value" : "Watertown"
},
{
"offset" : 29,
"value" : "MA"
},
{
"offset" : 33,
"value" : "United States"
}
],
"types" : [ "route", "geocode" ]
},
Details Request / Response from above prediction: https://maps.googleapis.com/maps/api/place/details/json?key=MYKEY&sensor=true&reference=CmRcAAAAzcupmv2dCaIWTnySJhA8y4BIc5_VSj1AUXCBFHEVnuo3NGjuqAVrLGSVZ_NODQstUs1ZclGASEzBYTF0B1nFSAcjgrc7Jn9NhJC2GZ2RtQQ3REFV7pvBzTPoGOHew289EhAD7dQFOe2EvBjpQ46IKODbGhTH0scvHs54U3refjf1-Tn6-04XvQ
{
"debug_info" : [],
"html_attributions" : [],
"result" : {
"address_components" : [
{
"long_name" : "98",
"short_name" : "98",
"types" : [ "street_number" ]
},
{
"long_name" : "Spruce St",
"short_name" : "Spruce St",
"types" : [ "route" ]
},
{
"long_name" : "Watertown",
"short_name" : "Watertown",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Middlesex",
"short_name" : "Middlesex",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Massachusetts",
"short_name" : "MA",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "02472",
"short_name" : "02472",
"types" : [ "postal_code" ]
}
],
"adr_address" : "\u003cspan class=\"street-address\"\u003e98 Spruce St\u003c/span\u003e, \u003cspan class=\"locality\"\u003eWatertown\u003c/span\u003e, \u003cspan class=\"region\"\u003eMA\u003c/span\u003e \u003cspan class=\"postal-code\"\u003e02472\u003c/span\u003e, \u003cspan class=\"country-name\"\u003eUSA\u003c/span\u003e",
"formatted_address" : "98 Spruce St, Watertown, MA 02472, USA",
"geometry" : {
"location" : {
"lat" : 42.3667790,
"lng" : -71.1698590
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
"id" : "5e66bbb5a5a7eaedd07fabc199e87570bcc0eae6",
"name" : "98 Spruce St",
"reference" : "CpQBhgAAABX6gm9Qh9r9QxMuEWIrwFGcsz2QnUG0MAoEkD33kwrxfcEakZh-d01oWlAFnIieF8MvVcflI7xJ91Qq2ahnw9oDjcUPUnhlRcOUjLF0lTXOWf3Fp3dbCqLo3MQxCDGT3UJj5fR4ZrPagqBYXtQcPl1TB6sgPHZv8x-2jdJzbh-yZ6yb9VhfG-KDD76-RdotkRIQ7Oz0mKuwaclr0xiIf4oHehoUM2l9nZsi5pU2RPyB7YA2lmJ7vI0",
"types" : [ "street_address" ],
"url" : "https://maps.google.com/maps/place?q=98+Spruce+St&ftid=0x89e3781f4bba528d:0xa7ec6e9a6bde2e4f",
"vicinity" : "Watertown"
},
"status" : "OK"
}
Upvotes: 3
Views: 1027
Reputation: 4850
You can't rely on the googleId thats returned by the autocomplete API. You need to use the reference, make an API call to Place Details API, then use that ID. I believe sometimes Google will consolidate their places database such that the reference will 'redirect' to a new place.
Upvotes: 0