Google Places API - Nearby Search not as accurate as Maps? - google-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.

Related

Google Places API: retrieve restaurant in Rome

It's hard for me to understand why Postman is returning me restaurant in US even if I'm restricting the research to postal_code:00100|country:IT (00100 = Rome zip code, IT = Italy)
This is my GET:
https://maps.googleapis.com/maps/api/place/textsearch/json?query=restaurant&components=postal_code:00100|country:IT&key=MYSECRETKEY
Where am I wrong?
The components filtering is not supported in Places API text search.
Take a look at official documentation, there is no components parameter available:
https://developers.google.com/places/web-service/search#TextSearchRequests
To bias your results you should use the location and radius parameters.
The components filtering is supported only in Geocoding API. So you can solve the issue in two steps.
Get position of the postal code using Geocoding API
Search restaurants using Places API text search and location from the first step
E.g.
Get location of postal code 00100
https://maps.googleapis.com/maps/api/geocode/json?components=postal_code%3A00100%7Ccountry%3AIT&key=YOUR_API_KEY
Now use coordinate 41.9228369,12.5014301 to search restaurants in 5km radius
https://maps.googleapis.com/maps/api/place/textsearch/json?query=restaurant&location=41.9228369%2C12.5014301&radius=5000&key=YOUR_API_KEY
Hope this helps!

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.

Locating current Google Place i'm at by latitude/longitude via Google Places API

i have a lat/long location data and i need to get current Google Place where i'm at now.
For example, if i'm in a shop(cafe, gym, etc..), i need to get info about THAT particular shop(cafe, gym, etc..).Or at least the closest one.
So, i'm doing it this way:
First i fetch place basic info(placeid,name, etc.) via Google Places API Nearby Search request:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=40.7597351,-73.9836576&radius=16.66&key=...
Then i find the closest one(which is apparently where i am) and perform Place Details request with it's placeid
So, everything works fine, except for some places like the one located at 40.7597351,-73.983657 (New York Guitar lab shop) which i can see on google map, but can't get in my response. Even places that are further from my location than this, are being found fine.
I've already tried to use rankBy=distance and then checking if the result is in required radius manually, still no use. Actually, maybe this approach is right, but as told in the docs, it's required to use types parameter with rankBy=distance. So, i set types=establishment since i actually need everything except addresses and locality tokens returned. I think that the problem is some places i need, are neither counted as establishments nor as localities, but i don't know the optimal way to exclude
all types specified at (https://developers.google.com/places/documentation/supported_types) Table 2 from my response. Is there a way to get only places which types are in Table 1 (except for specifying them ALL in my types param, haha)
So, could you please help me with how can i do this?
Thanks:)
P.S. here is very similar but unaswered question
Google Places API Displaying Inaccurate Result
It seems that there's explanation here (https://developers.google.com/places/faq#why_are_some_places_never_returned_even_though_they_have_google_pages). Looks like some places are just not yet verified by Google.
And yes, the establishment is the generic category for all non-localities. So you can be sure that if you set type=establishment then you'll have as much places as you will, if you'll specify all types from Table 2. Good Luck!

How can i force google autocomplete to not include any results that out for requested radius?

I've got a problem with Google Autocomplete rest api.
I need to return predictions only for certain radius, but "radius" parameter doesn't filter incorrect results. Currently I get results from another cities and even other countries.
How can i force google autocomplete to not include any results that out of requested radius?
The location and radius parameters only act as a bias to the results, there is currently no way to restrict results to a specific radius. You can however restrict results to a specific country by passing the components parameter as detailed in the documentation.
If you use the location, radius and component parameters you will most likely get the desired results.
An example search for Eiffel Tower, with a lat,lng location in Melbourne, Australia, radius 50km, and country restrict to Australia returns "Eiffel Tower Chocolate & Confectionery" as the real Eiffel tower is not within the radius or in the country that the request is restricted to:
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Eiffel+Tower&location=-37.816836,144.963123&radius=50000&components=country:au&sensor=false&key=your_api_key
You can use optional parameter radius.
radius — The distance (in meters) within which to return Place
results. Note that setting a radius biases results to the indicated
area, but may not fully restrict results to the specified area. See
Location Biasing.
The only way I can see to force this is to do the filtering yourself in the result array that you get when performing the search. I haven't used the Autocomplete API, but it seems you are using the Maps API to search? In that case, you get a GeocoderResult object which you can inspect the coordinates for the items, and compare them to your desired point and radius.
A bit hacky, but quite straightforward.
This example (uses the Google Maps API v3 places library):
http://www.geocodezip.com/v3_GoogleEx_place-search.html
from this answer:
Google places autocomplete - location and radius not working
uses rankby=distance
You can process the results to remove any not within your desired radius.

Google Places API returning sparse results vs Google Places iPhone app

I am building an application which uses Google Places API to show restaurants near my current location. For some reason the results are very sparse compared to the results that I can see from the Google Places iPhone application. For example from my rural home, Google Places app shows the nearest location 2.4 mi away. The Places API from this lat/long shows the nearest location 15.7 mi away.
Is it possible that "Google Places" the application is not using the Google Places API?
The Google Places App does not use the Google Places API so you will not see the exact same results, however you should see similar results.
A few tips when using the Places API:
The Places API by default sorts returned results in your selected radius by prominence, not distance. If you would like to find the closest places as it sounds like you are trying, use rankby=distance in your query with out the radius parameter.
Try using the keyword parameter instead of the 'name' parameter, as per the documentation: the 'keyword' parameter is matched against all available fields, including but not limited to name, type, and address, as well as customer reviews and other third-party content, this tends to return more results.
If you adhere to these tips you will most likely get similar results to Places App.