The below doc says by default the units will show based on the origin. https://developers.google.com/maps/documentation/distance-matrix/overview#units
I am testing with two addresses both in USA. I am expecting the distance to show in miles but it shows in km. Any idea how to get the results as per the documentation. Below is my test query (removed the API Key). I am not sending the units here as per the doc it should be handled automatically by the origin?
https://maps.googleapis.com/maps/api/distancematrix/json?origins=40.56289771529413,-74.32660038907106&destinations=40.86257148047112,-74.77304115053154&key=MY_API_KEY
Related
I used Nearby Search of Google Places API and sent a request with the radius parameter having a value of 1000 meters. My assumption is that the distance between any of search result and the target location will be less than 1km. But the API response gave me results that is beyond the 1km radius (like 1.3km).
I want to know if is this normal?
The Nearby Search radius parameter does not restrict the results to be within the circle.
Here's what the docs says:
"You may bias results to a specified circle by passing a location and a radius parameter. Doing so instructs the Places service to prefer showing results within that circle; results outside of the defined area may still be displayed."
Thus, the Nearby Search is working as intended if it gives you results a little bit beyond your search biasing using the radius parameter.
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.
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
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.
Does anyone know if Google Maps consider elevations and the actual path on earth to calculate distance between two points or it only considers geographical locations for distance measurement?
If you are referring to using google.maps.DistanceMatrixRequest then yes, it considers the actual route when calculating distance, based on the option provided in travelMode
code.google.com reference
When there is no established route (at least known to google) i'm sure (from experience) the response is the distance 'as the crow flies' between 2 lat/long locations. [experience based off making the request for a path that bisected a large lake]