1
votes

Trying to understand why geocoding the location "Albany, OR, United States" with Google Maps API brings you to Albany, NY. If you change "OR" to "Or" or "or" then it will correctly geocode to Albany, OR. Also if you remove the commas it will correctly geocode as well. See for yourself: https://developers.google.com/maps/documentation/geocoding/intro

Any ideas?

1
If you remove the "United States", it also works. - geocodezip
@geocodezip is a legend, do you have twitter? - noogui
@geocodezip Correct! The main reason it is formatted above with "United States" is because that is how it is returned by autocomplete using the Google Places API. Therefore, using autocomplete causes the wrong location to be returned. - roubix

1 Answers

0
votes

As I understood from the previous comments, you are using a place autocomplete.

You can get a place ID from the autocomplete instead of the text and use the place ID in the geocoding request. This approach works much better and this is a recommended way, according to the best practices document.

Google also has an example for Maps JavaScript API where they use a place ID obtained from the autocomplete to geocode features.

Please have a look and try this example with the 'Albany, OR, United States':

https://developers.google.com/maps/documentation/javascript/examples/places-placeid-geocoder

Hope it helps!