Search code examples
google-maps-api-3google-places-api

Google Maps Autocomplete Place returns incorrect result


We are using the Google Maps Autocomplete functionality on our web site and I have found an instance where the address entered into the entry field is not reflected upon selection in the Place object. The dropdown shows the proper address; but when selecting the item from the dropdown, a different City is returned. Here are the results from the API calls in my case. The address that is erroring is 31900 S Las Vegas Blvd, Primm, NV 89019, USA

Autocompletion call:

https://maps.googleapis.com/maps/api/place/js/AutocompletionService.GetPredictions?1s31900%20S%20Las%20Vegas%20Blvd%2C%20Prim%2C%20NV%2089019%2C%20USA&4sen-US&7scountry%3Aus&15e3&20sE64F37BA-8B6D-4A33-86BE-83F54790D5472pjedyc73ylv&21m1&2e1&callback=_xdc_._dz8gxh&key=xxxxx&token=xxxx

Autocompletion response (note that Primm is the returned city in the response):

[0,[["31900 S Las Vegas Blvd, Primm, NV 89019, USA",null,["premise","geocode"],"ChIJ10dOFw9Ez4ARmRsXd3LXKB0",null,[["31900",0],["S Las Vegas Blvd",6],["Primm",24],["NV",31],["89019",34],["USA",41]],[[0,5],[6,16],[24,5],[31,2],[34,5],[41,3]],null,"ChIJ10dOFw9Ez4ARmRsXd3LXKB0",["31900 S Las Vegas Blvd","Primm, NV 89019, USA",[[0,5],[6,16]],[[0,5],[7,2],[10,5],[17,3]]]],["31900 S Las Vegas Blvd, Primm, NV 89054, USA",null,["street_address","geocode"],"EiwzMTkwMCBTIExhcyBWZWdhcyBCbHZkLCBQcmltbSwgTlYgODkwNTQsIFVTQSIyEjAKFAoSCft3o2d4Sc-AEYLrJ4-B0RgjEJz5ASoUChIJ07Ypyp3DyIARp-OXpm9DxRM",null,[["31900 S Las Vegas Blvd",0],["Primm",24],["NV",31],["89054",34],["USA",41]],[[0,22],[24,5],[31,2],[34,5],[41,3]],null,"EiwzMTkwMCBTIExhcyBWZWdhcyBCbHZkLCBQcmltbSwgTlYgODkwNTQsIFVTQSIyEjAKFAoSCft3o2d4Sc-AEYLrJ4-B0RgjEJz5ASoUChIJ07Ypyp3DyIARp-OXpm9DxRM",["31900 S Las Vegas Blvd","Primm, NV 89054, USA",[[0,22]],[[0,5],[7,2],[10,5],[17,3]]]]]]

Selecting a response from the dropdown causes the following:

Request

https://maps.googleapis.com/maps/api/place/js/PlaceService.GetPlaceDetails?2sen-US&10e3&14m1&1sChIJ10dOFw9Ez4ARmRsXd3LXKB0&15sE64F37BA-8B6D-4A33-86BE-83F54790D5472pjedyc73ylv&16m1&1saddress_com

Response (Note that the city / locality is Jean instead of Primm):

{
   "html_attributions" : [],
   "result" : {
      "address_components" : [
         {
            "long_name" : "31900",
            "short_name" : "31900",
            "types" : [ "street_number" ]
         },
         {
            "long_name" : "South Las Vegas Boulevard",
            "short_name" : "S Las Vegas Blvd",
            "types" : [ "route" ]
         },
         {
            "long_name" : "Jean",
            "short_name" : "Jean",
            "types" : [ "locality", "political" ]
         },
         {
            "long_name" : "Clark County",
            "short_name" : "Clark County",
            "types" : [ "administrative_area_level_2", "political" ]
         },
         {
            "long_name" : "Nevada",
            "short_name" : "NV",
            "types" : [ "administrative_area_level_1", "political" ]
         },
         {
            "long_name" : "United States",
            "short_name" : "US",
            "types" : [ "country", "political" ]
         },
         {
            "long_name" : "89019",
            "short_name" : "89019",
            "types" : [ "postal_code" ]
         }
      ],
      "adr_address" : "\u003cspan class=\"street-address\"\u003e31900 S Las Vegas Blvd\u003c/span\u003e, \u003cspan class=\"locality\"\u003eJean\u003c/span\u003e, \u003cspan class=\"region\"\u003eNV\u003c/span\u003e \u003cspan class=\"postal-code\"\u003e89019\u003c/span\u003e, \u003cspan class=\"country-name\"\u003eUSA\u003c/span\u003e",
      "formatted_address" : "31900 S Las Vegas Blvd, Jean, NV 89019, USA",
      "geometry" : {
         "location" : {
            "lat" : 35.6101639,
            "lng" : -115.3921341
         },
         "viewport" : {
            "northeast" : {
               "lat" : 35.6115836802915,
               "lng" : -115.3906660197085
            },
            "southwest" : {
               "lat" : 35.6088857197085,
               "lng" : -115.3933639802915
            }
         }
      },
      "name" : "31900 S Las Vegas Blvd"
   },
   "status" : "OK"
}

Does anyone know why this is happening? Is this a bug on the Google server or is there something I can correct on my side? I am using Google Maps API 3.43.3


Solution

  • Three things are happening, two are intended behavior (how the Places API works by design), and one that looks like it may be incorrect:

    1. Intended Behavior: Place Autocomplete returns "Primm" in the (first) prediction.description because it is present in the user input (31900 S Las Vegas Blvd, Prim, NV 89019, USA as extracted from your Autocomplete request) and is close enough. This is so that predictions can be returned for the place a user wants even if the city in their input is not exactly correct, nearby cities are allowable. Place Autocomplete prioritizes the user input when formatting address for predictions, so it will show the city name from user input even if it's not exactly the same as the city name in the prediction's actual address.

    2. Intended Behavior: Place Details returns "Jean" as the city name because that is the one in this place's actual address in Google Maps.

    3. Possibly Incorrect: This place has the city of "Jean" in its address, even though it looks like it's in, or at least much closer to, Primm. I have seen cases where US addresses do that on purpose, but if you know for a fact (first-hand local knowledge), you can use the "Send feedback" link at the bottom right corner in Google Maps to send a correction for that place's address.