The difference of the Geocoder result and autocomplete

603 views Asked by At

I'm making the airbnb clone now. In this application I'm using geocoder gem and google autocomplete.

In the top page, there is a search form. In that form I'm using autocomplete and Geocoder.

When user select autocomplete field I get lat and lng from autocomplete.

When user doesn't select autocomplete suggestions, they get the lat and lng data from the Geocoder.coordinates.

The problem is when user selecet "Mariana bay sands singapore" in autocomplete, it returns the lat and lng params.

But user type the "Mariana bay sands singapore" in the search form (not select auto complete suggestions), it doesn't return the lat and lng params.

How can I get the lat and lng params like airbnb?

1

There are 1 answers

0
mxlse On BEST ANSWER

The autocomplete function is part of the Places library - that's why you don't receive a result with a postion using the geocoder while the autocomplete selection provides a latlng for your query.

Using the Places API should do the trick in your case. Example: https://maps.googleapis.com/maps/api/place/textsearch/xml?query=Mariana+Bay+Sands+Singapore&key=YOUR_API_KEY

The Geocoder API should be used for addresses only, while the Places API and Places Autocomplete can be used for semantic locations and addresses (including POIs or businesses like in your example). For further information read this blog post.