Google Places API: retrieve restaurant in Rome - json

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!

Related

How to find municipality and postal code that are in range from coordinates?

Is there a way by using azure-maps or google-maps to get from longitude and latitude all postal codes and municipalityes that are in range of X kilometers?
I've yet checked the Get Search Nearby of azure, but it returns only points of interests and it is not possible to specify in the API a range in which the data should be get.
In Azure Maps, getting all postal code/municipalities within a specified distance of a location or within an area is not currently available. However, this is something being investigated as a possible future service. Consider submitting this as a feature request here: https://feedback.azure.com/forums/909172-azure-maps
I don't believe Google Maps has any such service either.

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.

Calculating distance with pincode (Google map Distance Matrix API)

I am developing web application on MVC, I have a requirement to automatically find the distance between two locations using the pin code. So, I started using the google map distance matrix API as below:
https://maps.googleapis.com/maps/api/distancematrix/xml?origins=" + Convert.ToString(origin) + "&destinations=" + Convert.ToString(destination) + "&key='MY key'
API is working fine for pin codes of India, but I have to deploy the application on Cambodia and for Cambodia pin code the API is not working.
Can anyone help me, please?
I've had a look at your request https://maps.googleapis.com/maps/api/distancematrix/xml?origins=12413&destinations=12211&key=YOUR_API_KEY
Please note that 12413 and 12211 in origins and destinations parameters are very ambiguous values. You have to provide more precise addresses in order to get results. The Distance Matrix API will geocode the 12413 and 12211 internally.
For example, the 12413 will be geocoded to 'Cairo, NY 12413, USA' a postal code in the USA. You can see this in Geocoder tool:
https://developers-dot-devsite-v2-prod.appspot.com/maps/documentation/utils/geocoder/#q%3D12413
The 12211 will be geocoded to 'Albany, NY 12211, USA':
https://google-developers.appspot.com/maps/documentation/utils/geocoder/#q%3D12211
In both cases it's not a pin code in Cambodia as you expect.
Even more, when I try to find a postal code 12413 or 12211 in Cambodia using a component filtering I get ZERO_RESULTS:
https://developers-dot-devsite-v2-prod.appspot.com/maps/documentation/utils/geocoder/#in_postal_code%3D12413%26in_country%3DKH%26options%3Dtrue
https://developers-dot-devsite-v2-prod.appspot.com/maps/documentation/utils/geocoder/#in_postal_code%3D12211%26in_country%3DKH%26options%3Dtrue
Attempts to get postal code from reverse geocoding of coordinate in Cambodia also lead to ZERO_RESULTS:
https://maps.googleapis.com/maps/api/geocode/json?latlng=11.55486%2C104.905679&result_type=postal_code&key=MY_API_KEY
Although the locality for the same coordinate can be found:
https://maps.googleapis.com/maps/api/geocode/json?latlng=11.55486%2C104.905679&result_type=locality&key=MY_API_KEY
It's 'Phnom Penh' with place ID ChIJ42tqxz1RCTERuyW1WugOAZw.
Taking into account all these facts it looks like Google doesn't have pin code information for Cambodia in their database.
I can suggest using a place autocomplete in your application. This way the user can select a suggested address and you can use a place ID selected by user to execute distance matrix requests. Have also a look at geocoding best practices in official documentation:
https://developers.google.com/maps/documentation/geocoding/best-practices
I hope this helps!

Google Directions API Result is different from Google Maps result

I am developing an app that displays the Distance & path between 2 distances. In this case I have used following addresses:
Source: Major Bhola Ram Enclave
Destination: Ring Road Mall, Sector 3, Rohini, New Delhi, Delhi
When I use Directions API then I get following result, see image below:
But, when I search these addresses in Google Maps then I get different Result.
Click here to see Google Maps result
I searched a lot about this but I couldn't find any reason/solution for this.
Please guid me in right direction.
Thanks.
Those are not addresses, they are places. If you want a similar result to Google Maps, you need to use the placeId or the coordinates returned for that place from the places service in the directions request.
http://www.geocodezip.com/v3_example_geo2.asp?addr1=Major%20Bhola%20Ram%20Enclave&addr2=Ring%20Road%20Mall,%20Sector%203,%20Rohini,%20New%20Delhi,%20Delhi&place=1&place=2
(uses the results from the place service)

Why do I get different result from geocode api vs google maps

I am new to google geocode API but I am planning to use the free version to get map coordinates for nearby golf courses. I started with my home course:
http://maps.google.com/maps/api/geocode/json?address=Karlstad+golfklubb
Plus "&key=[my generated api key]"
I get a result with status="OK" but the resulting long/lat is not correct. It's near but misses with 7-8km.
When I use maps.google I get correct location. Searched for "Karlstad golfklubb".
https://www.google.se/maps/place/Karlstad+Golfklubb/#59.4346545,13.5140563,17z/data=!3m1!4b1!4m2!3m1!1s0x465cb41aca8c1467:0x64836d18f18df2f6
Why do I get different geo locations when using the same keywords. Do they operate on different databases or do I need to enter more params?
I also tried with other nearby courses like "sommarro" and "bryngfjorden" but for they I get zero result. But no problem finding them in google maps.
If you look at the JSON code, they describe the formatted_address as
"formatted_address" : "Karlstad Golfbanan Jako, 652 30 Karlstad, Sweden"
Which if you enter into Google Maps shows the correct longitude and latitude in the JSON.
https://www.google.com/maps/place/Karlstad+Golfbanan+Jako,+Sweden/#59.3602394,13.472185,17z/data=!3m1!4b1!4m2!3m1!1s0x465cb23bc0f46911:0x66ceae446bdc95dc