8
votes

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?

1
When i use javascript interface it does. Try to add street address. It will return multiple results. maps.googleapis.com/maps/api/geocode/…Mike Kor
I would guess that "Smith Street" is even more ambiguous than "Smith Street 10" so that doesn't really explain the behaviour.MrUpsidown
the geocoder may return several results ...."may" doesn't mean he always will.Dr.Molle
Agreed. But it would be nice if we had an idea of why/when it would consider an address lookup as "ambiguous"...MrUpsidown
I agree that the behaviour does match what the API doc says, but it seems deliberately vague.glosrob

1 Answers

13
votes

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