Google Maps Geocode - Never returns multiple results - json

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?

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

Related

Google Places API - Nearby Search not as accurate as Maps?

Overall goal: map a list of completely unknown GPS coordinates to closest points of interests (I dont know if the coordinates are referring to a shop, mountain, museum etc.).
The Google Place API, exactly the Nearby Search (https://developers.google.com/places/web-service/search?hl=de#PlaceSearchRequests), is theoretically solving my problem: I can pass GPS coordinates and a radius and get a list of "places" back.
Unfortunately, the results are not really precise. However if I "google" the very same coordinates in Maps, I get very satisfying results.
Examples:
48.12429, 11.56774:
Maps shows shop "Kenneth Kobonpue" really close by;
API call with radius 10/50/100 does not mention this shop at all
48.15100, 11.57964:
Maps shows University of Munich;
API call with radius 10/50/100 just mentions some special university rooms
48.16404, 11.60370:
Maps shows "English Garden" (park in Munich);
API call with radius 10/50/100 does not mention this park once
etc.
Question: Is there an option to get better results using this API? Is there another (Google) API more suitable to my usecase?
Google Maps(maps.google.com) and Google Maps Platform APIs are two different products and will behave differently at times. Their features, results and behaviors are not expected to be always the same.
In general, Places API requests returns the prominent places depending on the parameters you have provided. It is possible that the place you are looking for is not a prominent point-of-interest given the distance from your location.
Taking your sample for the location, "48.16404, 11.60370", you'll get the expected "English Garden" in a distance of 500. Here's a sample request: https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=48.16404%2C%2011.60370&radius=500&key=YOUR_API_KEY
Another alternative is to use the "rankby" parameter and set it to "distance". This will bias the results according to their distance from the given location. However, you need to specify one or more of the following parameters: keyword, name, or type (required parameters if results are rank by distance). Here's another example: https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=48.16404%2C%2011.60370&keyword=garden&rankby=distance&key=YOUR_API_KEY
In addition, by default, each Nearby Search returns up to 20 establishment results per query only. However, each search can return as many as 60 results, split across three pages. It is also possible that the point of interest you are looking for is in the succeeding pages. You can use the next_page_token parameter in another search request to access additional results.
For more information regarding Places Nearby search, you can checkout this link: https://developers.google.com/places/web-service/search#PlaceSearchRequests
This seems to be a recent bug, I am pretty sure I saw thsi working before.
Maps search shows very different set of places vs
using the APi, regardless of ranking parameter https://maps.googleapis.com/maps/api/place/nearbysearch/json?keyword=grocery&radius=5000&location=51.5183332%2C-0.2752538&key=[YOUR_KEY_HERE]
In this case, it is very clear that the platform API returns incorrect results using a different center point than the parameter provided.

Google Places API Text Search doesn't filter address correctly

I am using Google Places API Text Search to fetch for pharmacies and looks like it isn't filtering address correctly.
When I search for Walgreens, it returns some results from Broadlands, Herndon and some other locations.
If I search for Walgreens Broadlands or Walgreens Herndon, it returns nothing.
But if I search for Walgreens Miami or Walgreens Village it returns correctly.
Other strange behaviour is that, sometimes, executing the same request two times returns different results. For that reason, I don't know if you will get the same results using the links I provided.
Google documentations states the following:
The service is especially useful for making ambiguous address queries in an automated system, and non-address components of the string may match businesses as well as addresses. Examples of ambiguous address queries are incomplete addresses, poorly formatted addresses, or a request that includes non-address components such as business names.
From my understanding, the examples I gave should work just fine.
Am I missing something? What is wrong in these cases?
It sounds like a bug, I would suggest filing an issue in Google Issue tracker for Places API.
The unique workaround I can think about is providing an additional information about the area where you are searching the Walgreens pharmacy. I believe the queries with location bias work better than without it. If I use the coordinate of Broadlands (39.0181644,-77.5202688) and specify radius of 50 km, the Places API text search for Walgreens return results
https://maps.googleapis.com/maps/api/place/textsearch/json?query=walgreens&location=39.0181644%2C-77.5202688&radius=50000&type=pharmacy&region=US&key=MY_API_KEY
as shown in the screenshot
I hope this helps!

Find city in Google Geocoding API

I am using google Geocoding API to store the cities in the DB on demand.I provided an input field for the user to enter their city.I used googles places autocomplete for that.
I would like to store the city and its country what ever enter ed in the input field. Calling google geocoding API with the with data from input field, returned data in JSON.
I looked into address_components got country in it. Then I took object in address_components where types = locality. The problem is,For some locations typed in the input field, The JSON from google geocoding API doesn't have types = locality. So in these cases, which one among the objects in address_components should I store as city in my DB.
this website is exampale of google geocoding api https://findcity.in/
Need suggestions. The question may not be clear earlier. So I edited it. Thanks
You are right, the type locality is not always present in the address components array. Depending on the country or even regions of the same country the city name might be found in different address components. This depends on the data modelling for certain area and address templates that uses Google. Unfortunately, there is no documentation for this on per country basis.
In the official documentation you can find the following explanation
The selection of specific address components in this example is based on a typical address format. You may need to select different components to align with the postal address formats of different countries. For example, the code selects the locality component, which often represents the city part of the address. However, note the following examples of how the components may differ:
In the UK and Sweden the correct component to display the city is postal_town.
In Japan, the component differs across prefectures.
Brooklyn and other parts of New York City do not include the city as part of the address. They use sublocality_level_1 instead.
source: https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-addressform
I hope this helps a bit.
administrative_area_3 indicates a third-order civil entity below the country level.
An example of this would be a search query for Montgomery returning Montgomery County in your specific state before Montgomery, AL. This is partially due to region biasing returning specified results based on your current location.
Here is some documentation from Google Which goes over the GeocoderResult.
I'd like to encourage you to make sure to take a look at the Google Maps APIs reference guide before asking a question directly. It is rather robust and you can find a lot of useful information there.

google places and geocode not returning full results list

I am doing some mapping work and need to find latitude and longitude of villages in india many of which are small and rural. I am having trouble finding the full set of locations with the same name, for example a village named 'Kallanai' (see api links below, note they need appropriate keys for the places API to run on your computer). I can find the one I'm looking for in google maps by entering www.google.co.in/maps/place/Kallanai into the browser however it will not turn up in the geocoder or places api without specifying the associated pin code (analogous to zip-code). Can anyone explain why the basic searches for either the geocode or places API using the village name alone do not return the village with the pincode 625501 in the results?
e.g.
Google places:
https://maps.googleapis.com/maps/api/place/textsearch/json?query=kallanai&sensor=false&key=enter your key
https://maps.googleapis.com/maps/api/place/textsearch/json?query=kallanai+625501&sensor=false&key=enter your key
will post google geocode links in follow up as stackoverflow will not let me include more than 2 links in my post without more points.
In a world where autocomplete is common and almost taken for granted, Google Maps has (long) switched to showing just the one results your most likely looking for.
Places Autocomplete API might get you more of what you're looking for, but it would still be a sub-optimal fit for database-like queries like this. It works best when you have users typing, each of them knowing which Kallanai they want, so they can select the suggestion that matches, and they can add details (e.g. PIN code) to get it if the suggestion doesn't show up at first (max 5 suggestion show each time).
Google does Geocoding in a different way from classic GIS databases. To obtain all cities [with a given name] in a given country, you'd probably need a database like GeoNames or Natural Earth.

Localities around a particular latlang

I require list of localities around a particular latitude and longitude through Google Places.
Currently I'm making a call as
https://maps.googleapis.com/maps/api/place/search/json?location=12.96207210,77.71577370&radius=3700&types=political&sensor=false&key=API_KEY
However,it is returning only those places which are approximately 3700 m far from that place.
I require all places returned in the output.
It appears that you are trying to retrieve all locality results close to you, as you are type filtering your request by type political.
Unfortunately the Google Places API is not designed for this and will only returning two political and locality results per request for area identification.
If you think that returning more than two political or locality results per request would be a useful feature for the Google Places API, you can submit a 'Places API - Feature Request' here.