Evan Knowles
Evan Knowles

Reputation: 7511

Google Maps autocomplete prompt does not match returned location

Google Maps autocomplete is working in almost all cases, but behaves strangely on one address.

JSFiddle, thanks to @geocodezip, showing the issue.

This is similar to this issue, except in that issue no place was returned. This returns a similarly named place, but in a different location.

The correct address appears in the suggestions box, but is different on the place_changed event. The two addresses are located a large distance from one another.

Differing results for autocomplete

As can be seen, this is reproducible on the autocomplete demo, so I don't think it's an implementation issue. Has anyone seen this kind of behaviour and managed to fix it?

In addition, requesting query predictions via the AutocompleteService for the address that is returned by the original autocomplete suggestion returns ZERO_RESULTS.

new google.maps.places.AutocompleteService();
    service.getQueryPredictions({ input: '77 Main Road, Crowthorne AH, Sandton, South Africa' }, function(predictions, status) {
      if (status != google.maps.places.PlacesServiceStatus.OK) {
        alert(status);
        return;
      }

      predictions.forEach(function(prediction) {
        console.log(prediction);

      });
    });

Upvotes: 1

Views: 2452

Answers (1)

xomena
xomena

Reputation: 32178

The issue that you are experiencing was reported in Google issue tracker. You can have a look and add your comment here:

https://issuetracker.google.com/issues/35830687

Let me explain what is the problem. If you check the place ID documentation, you will see that there are two options for place IDs.

https://developers.google.com/places/place-id#id-overview

The short place IDs like ChIJrTLr-GyuEmsRBfy61i59si0 and the long place IDs like EisxMyBNYXJrZXQgU3RyZWV0LCBXaWxtaW5ndG9uLCBOQyAyODQwMSwgVVNB. When you see the short place ID that means Google has an exact feature for this address in their database, when you see the long place ID that means Google doesn't have an exact feature and tries to interpolate an address. Sometimes the interpolation works differently in autocomplete and in place details, so in this case you observe the issue described in your question and reported as bug 35830687.

Now let's check what is the place ID in your example. I execute the following place autocomplete request:

https://maps.googleapis.com/maps/api/place/autocomplete/json?input=77%20Main%20Road%2C%20Crowthorne%20AH&key=API_KEY

I can see the following text in the response

"predictions":[
  {
    "description":"77 Main Road, Crowthorne AH, Sandton, South Africa",
    "id":"a0ab043870d062bad00d5ce2ed91faaf7250efbe",
    "matched_substrings":[
      {
        "length":12,
        "offset":0
      },
      {
        "length":13,
        "offset":14
      }
    ],"place_id":"EjI3NyBNYWluIFJvYWQsIENyb3d0aG9ybmUgQUgsIFNhbmR0b24sIFNvdXRoIEFmcmljYQ",
....

The place ID is the long one EjI3NyBNYWluIFJvYWQsIENyb3d0aG9ybmUgQUgsIFNhbmR0b24sIFNvdXRoIEFmcmljYQ and that means the address is interpolated.

The most straight forward fix might be creating an exact address for '77 Main Road, Crowthorne AH, Sandton, South Africa'. There is only one way to report missing data to Google and it's described in the following support help:

https://support.google.com/maps/answer/3094045

You should send feedback and let Google know that address '77 Main Road, Crowthorne AH, Sandton, South Africa' is missing. Otherwise you should wait while bug 35830687 is solved.

I hope this explains your doubt!

Upvotes: 2

Related Questions