Localities around a particular latlang - google-maps

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.

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.

Geocode API coordinates not recognized by the reverse geocode API (ZERO_RESULTS)

If I check the coordinates for a location by making a request to the Geocode API like this https://maps.googleapis.com/maps/api/geocode/json?address=Los%20Angeles,%20CA,%20United%20States&key=your-browser-key
Then it returns 34.0522342,-118.2436849 for LA, if I then go the reverse geocode API and enter those coordinates then it shows no results?
How's that possible? API a returned a set of data that's not recognized by API b? Shouldn't they both use the same data?
Is this some kind of bug, or am I doing something wrong somewhere?
I've just gotten the following message from Google
Dear Maps APIs Premium Plan customers,
Reverse geocoding results in the Geocoding API will soon be updated to provide better quality worldwide. While the new results will often be different from the current results and contain different Place IDs, they should not require adjustments in client applications.
The new results are currently rolled out to non-Premium-Plan users. We plan to make the new results the default for Premium Plan customers on September 17th 2018.
Applications can preview the new results ahead of September 17th by adding the new_reverse_geocoder=true parameter to their Geocoding API requests. Please note that adding this parameter to requests without the latlng parameter will result in an error response (INVALID_REQUEST).
The new results can also be visualized by clicking on the base map (or entering a latlng) in the Geocoder Tool at https://google-developers.appspot.com/maps/documentation/utils/geocoder/
The new results provide the following improvements:
Increased ratio of rooftop results in favor of interpolated addresses.
Decreased ratio of requests receiving only political results like a city or a neighborhood (ie, incomplete addresses).
Decreased distance from input latlng coordinates to the nearest result.
In areas with sparse coverage, establishments are returned in addition to geocodes.
Decreased ratio of requests receiving results more than 400 meters from the input latlng.
Please let us know if you find issues with the new results. Quality issues are best reported in the Maps API public issue tracker at https://issuetracker.google.com.
So, as you can see Google is launching a new version of reverse geocoder. I've tried your request with old version adding the &new_reverse_geocoder=false parameter and got results
https://maps.googleapis.com/maps/api/geocode/json?latlng=34.0522342%2C-118.2436849&new_reverse_geocoder=false&key=MY_API_KEY
At this point it looks like regression in new version of reverse geocoder.
Update
Google tracks this issue in the bug:
https://issuetracker.google.com/issues/115484101

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 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?
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

Google Places API vs. Google Geocode API

I have implemented Google Places API with autocomplete and Google Geocoding Api. The problem is that it seems that the results do not work correctly.
Sometimes some of the choosen results from the autocomplete list do not geocode at all, all i get is the status ZERO_RESULTS.
I know that there could be some problems regarding the fact that Google Autocomplete uses also Places, while Google Geocode uses only postal codes, but how could i limit autocomplete to give me only postal codes results.
Place Types
You may restrict results from a Place Autocomplete request to be of a certain type by passing a types parameter. The parameter specifies a type or a type collection, as listed in the supported types below. If nothing is specified, all types are returned. In general only a single type is allowed. The exception is that you can safely mix the geocode and establishment types, but note that this will have the same effect as specifying no types. The supported types are:
geocode instructs the Place Autocomplete service to return only geocoding (address) results. Generally, you use this request to disambiguate results where the location specified may be indeterminate.
establishment instructs the Place Autocomplete service to return only business results.
the (regions) type collection instructs the Places service to return any result matching the following types:
locality
sublocality
postal_code
country
administrative_area1
administrative_area2
the (cities) type collection instructs the Places service to return results that match either locality or administrative_area3.
Hope this helps
https://developers.google.com/places/documentation/autocomplete
There is no way to achieve it via an Autocomplete.
When you type in a autocomplete the API first will request the predictions, but not the details.
This means that at the time when you see the predictions it's still not clear if there are details available for this place.
There are cases when the particular place can't be found. I'm sure when it would be possible for google to exclude the missing places they wouldn't return them at all.
The only workaround I see would be to create the autocomplete on your own by requesting both, predictions and details , before you apply the predictions. But note: each time the user types into the input this will count as 6 requests(assuming 5 predictions will be returned)