admin管理员组

文章数量:1317906

I have an input field (let's call it $addressInput) in which I ask the user to provide his address.

I then use this address in my back-end to retrieve the latitude and the longitude of the address.

For some addresses, like for example this one "214 Avenue du Général Leclerc, Eaubonne, France", if a user enters this address, google maps autoplete will suggest two different addresses to the user in the autoplete dropdown. The first one (= suggestion A) is "214 Avenue du Général Leclerc, Eaubonne, France" and the second one (=suggestion B) is "214 Rue du Général Leclerc, Eaubonne, France".

But if the user clicks on suggestion A, although the input is filled with "214 Avenue du Général Leclerc, Eaubonne, France", the real formatted_address returned by google maps autoplete is not the same as suggestion A, it is "214 Avenue de la Division Leclerc, 95160 Montmorency, France".

Why doesn't google maps autoplete suggest straight away the real formatted_value in the dropdown? Why does it show the user an adress in the dropdown, but internally uses a different formatted address? Is it possible to force the autoplete API to display the formatted_address in the choice dropdown? In this case, I would have suggestion A = "214 Avenue de la Division Leclerc, 95160 Montmorency, France" (instead of "214 Avenue du Général Leclerc ...") and suggestion B = "214 Rue du Général Leclerc, Eaubonne, France"

Please find below the code that allowed me to know this:

var $addressAutoCompleteInput = $('.js-address-autoplete-input'); //this is my input

var addressAutoplete = new google.maps.places.Autoplete($addressAutoCompleteInput[0], {
    ponentRestrictions: {country: 'fr'}
});

addressAutoplete.addListener('place_changed', function() {
    console.log(addressAutoplete.getPlace().formatted_address)
});

The exact behaviour happens on the official page of google maps autopete

The marker shown on the map does not have the same formatted_address as the user input.

Thank you.

I have an input field (let's call it $addressInput) in which I ask the user to provide his address.

I then use this address in my back-end to retrieve the latitude and the longitude of the address.

For some addresses, like for example this one "214 Avenue du Général Leclerc, Eaubonne, France", if a user enters this address, google maps autoplete will suggest two different addresses to the user in the autoplete dropdown. The first one (= suggestion A) is "214 Avenue du Général Leclerc, Eaubonne, France" and the second one (=suggestion B) is "214 Rue du Général Leclerc, Eaubonne, France".

But if the user clicks on suggestion A, although the input is filled with "214 Avenue du Général Leclerc, Eaubonne, France", the real formatted_address returned by google maps autoplete is not the same as suggestion A, it is "214 Avenue de la Division Leclerc, 95160 Montmorency, France".

Why doesn't google maps autoplete suggest straight away the real formatted_value in the dropdown? Why does it show the user an adress in the dropdown, but internally uses a different formatted address? Is it possible to force the autoplete API to display the formatted_address in the choice dropdown? In this case, I would have suggestion A = "214 Avenue de la Division Leclerc, 95160 Montmorency, France" (instead of "214 Avenue du Général Leclerc ...") and suggestion B = "214 Rue du Général Leclerc, Eaubonne, France"

Please find below the code that allowed me to know this:

var $addressAutoCompleteInput = $('.js-address-autoplete-input'); //this is my input

var addressAutoplete = new google.maps.places.Autoplete($addressAutoCompleteInput[0], {
    ponentRestrictions: {country: 'fr'}
});

addressAutoplete.addListener('place_changed', function() {
    console.log(addressAutoplete.getPlace().formatted_address)
});

The exact behaviour happens on the official page of google maps autopete https://developers.google./maps/documentation/javascript/examples/places-autoplete?hl=fr

The marker shown on the map does not have the same formatted_address as the user input.

Thank you.

Share Improve this question edited Jun 24, 2018 at 18:36 xomena 32.2k6 gold badges96 silver badges125 bronze badges asked May 10, 2018 at 14:28 NadjibNadjib 3617 silver badges19 bronze badges 2
  • Why is it so, I don't work at Google so I can't tell you. Now a few things: 1) The address you are trying to use doesn't seem to exist and 2) if you want more control over the behavior of the autoplete, use the Autoplete Service class and build your own thing. See this answer for a full example. – MrUpsidown Commented May 10, 2018 at 16:23
  • Yes, the fact that the address does not exist is basically what makes Place Details find something else (that exists). In addition to issuetracker.google./issues/35823492 in the (very good) answer below, you might want to look at issuetracker.google./111160335 as well. – miguev Commented Jul 6, 2018 at 9:52
Add a ment  | 

2 Answers 2

Reset to default 5

To understand what is happening you should have a look at the place ID of the first suggestion. It is EjEyMTQgQXZlbnVlIGR1IEfDqW7DqXJhbCBMZWNsZXJjLCBFYXVib25uZSwgRnJhbmNl.

When you see these long place IDs instead of something like ChIJHzwQtJeLGGARxaSLI71pDSY that means the address doesn't exists in Google database. Autoplete accepts your input because they assume that you might know better than Google the exact address. So they create the interpolated place ID (the long one) and pass it to details. The details, however, searches existing places that might match the user's input, so they resolve you long place ID EjEyMTQgQXZlbnVlIGR1IEfDqW7DqXJhbCBMZWNsZXJjLCBFYXVib25uZSwgRnJhbmNl to the existing place ID ChIJ31WNvopo5kcRoAlv3ui0Aj0 214 Avenue de la Division Leclerc, 95160 Montmorency, France.

This misbehavior for interpolated place IDs was reported in Google issue tracker and it is handled in bug

https://issuetracker.google./issues/35823492

According to the last messages Google is currently working on solving this problem. Feel free to star the bug to add your vote and subscribe to notifications.

Is it possible to force the autoplete API to display the formatted_address in the choice dropdown?

In order to do this you need to create the missing address '214 Avenue du Général Leclerc, Eaubonne, France' in Google database. The only option is report missing address to Google sending a feedback as described in support help:

https://support.google./maps/answer/3094045?hl=en&ref_topic=3093612

Once Google adds missing address the autoplete should work as expected.

I'm facing the same issue for multiple addresses.

Ex.: I'm finding "601 Telegraph Canyon Road" and Google Map Address Autoplete is displaying us "Canyon Villa Apartment Homes, 601 Telegraph Canyon Road, Chula Vista, CA, USA" but actually in the formatted address of API is returning "601 Telegraph Canyon Rd, Chula Vista, CA 91910, USA".

Google Map Address Autoplete API:

So, What we can do as a solution. I'm contacting a name and formatted address to get nearly accurate data.

Name and Formatted Address from API:

I know, it's not a good solution but we have reported the same issue to Google. For now, we are following this solution.

If anyone has an exact solution then please let us know.

本文标签: javascriptGoogle Maps Autocomplete Formatted address is not the same as the displayed oneStack Overflow