Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps Geocode - Never returns multiple results

The Google Maps API documents online for their Geocode API states:

Generally, only one entry in the "results" array is returned for address lookups,though the geocoder may return several results when address queries are ambiguous.

However if you hit this example for 'Smith Street' (that counts as ambiguous, right?) you only get one result.

https://maps.googleapis.com/maps/api/geocode/json?address=smith%20street&components=country:GB

So if Smith Street isn't ambiguous, what is? Or is the reality that this API only ever returns one result?

like image 516
glosrob Avatar asked Jan 06 '16 07:01

glosrob


1 Answers

The docs are so misleading when it insinuates that you can search for places and get all locations based on a place name or ambiguous address. Actually, they always returned either zero or one result only in all my trials.

Example:

*Searching "KFC" returns zero results!

*Searching "KFC berlin" returns one result!


In summary, if you don't have a precise address, do not use geocoding to retrieve lats and longs period!

Instead, you should use "Place search", explained Here.

Why? If you check this Google Maps API blog, it says:

The Geocoding API is best for handling unambiguous queries such as complete postal address strings. Geocoding API is not recommended if your application handles ambiguous or incomplete queries, such as “123 Main St”, or if it handles queries that may contain non-address information such as apartment numbers or business names.

However, the "Place search" using Places API is much smarter at searching Semantic locations and addresses, including businesses and points of interest.

If you want to make the user search for places using GUI, you can use "Places autocomplete", but they also would mark a single location on the map based on the exact choice the user selects from the autocomplete list. You can find a tutorial Here

like image 169
Mena Avatar answered Sep 25 '22 03:09

Mena