Google Maps API: Different formats of place_id value - google-maps

I'm using getQueryPredictions method to get autofill entries. The value of place_id in about 10% of returned places is a 40 characters long string that starts with "E". I'm trying to pass that place_id to google.maps.DistanceMatrixService().getDistanceMatrix method to get a distance between those places and other "normal" locations but Google does not return anything for such IDs.
You can easily get such "E" place_id if you use address "4498 INTERSTATE NORTH PARKWAY EAST SOUTHEAST" at this form from Map API Documentation It returns "EjM0NDk4IEludGVyc3RhdGUgTiBQa3d5IEUgU0UsIEF0bGFudGEsIEdBIDMwMzM5LCBVU0E" as place_id. Use that ID in any other Maps API mathods and Google won't recognize it as a valid place_id.
How can I use those weird IDs to look up distances? Or how can I transform them into normal place_ids?

I created an API key and used the referred place_id, which returned a valid response.
https://maps.googleapis.com/maps/api/place/details/json?placeid=EjM0NDk4IEludGVyc3RhdGUgTiBQa3d5IEUgU0UsIEF0bGFudGEsIEdBIDMwMzM5LCBVU0E&key=[API_KEY]
Its not specified, but not all Google Maps API can be used with place_id.
You can use the same place ID across the Google Places API and a number of Google Maps APIs. For example, you can use the same place ID to reference a place in the Places API, the Google Maps JavaScript API, the Google Maps Geocoding API, the Google Maps Embed API and the Google Maps Roads API.
For your getDistanceMatrix to work, your destinations[] should either be string, LatLng, or Place objects. You'll have to use the place_id to get the place details (which has the LatLng that you can use for getDistanceMatrix).

Related

Get all geolocations by partial name using google maps api

I have signed up with the Google Maps API. I can geolocate locations using the following query
url = f"https://maps.googleapis.com/maps/api/geocode/json?address={city}&key={api_key}"
I need to do a search for towns by partial name.
For example 'MyTown' is a town , but there are also towns with names which include 'MyTown' in the title, such as MyTown-By-Sea, MyTown-SomethingElse and even NiceMyTown
The above query using the API returns just the city MyTown, not the others
Is there some option I have missed to get the Google Maps API to be less specific in the response returned ?
You can use Places Autocomplete API web service. This API will return places suggestions or predictions, based on your given input.
https://maps.googleapis.com/maps/api/place/autocomplete/json
?input=MyTown (based on your example)
&location=latitude,longitude
&key=YOUR_API_KEY

How to display road name in marker infowindow while displaying route in google maps?

I need road name in marker infowindow while displaying route in google maps.
I found the following options,
1. Geocoder service in Google Maps Javascript API - which will give address for the given GPS coordinate.
2. Google Maps Roads API - which will return placeIds of the path and again I need to fire another request to get the address of placeId
What will be optimal solution to retrieve the road name for a given route (array of gps coordinates)?
The Geocoding API is the appropriate API to use for converting lat/lng coordinates into textual addresses and vice-versa. It's what it's meant to be used for.
The following is an example of a reverse geocoding request:
https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&key=YOUR_API_KEY
Hope this helps!

Google Maps API V3 difference vs Google Maps page [duplicate]

Why do calls to the Google Maps Geocoder API return different results than what I see in my browser?
This one returns many items :
http://maps.google.fr/maps?q=McDonald,+paris
This one returns a ZERO_RESULT :
http://maps.googleapis.com/maps/api/geocode/xml?McDonald,+paris&sensor=false
FAQ: https://developers.google.com/maps/faq#geocoder_differences
The API geocoder finds postal addresses. The Maps geocoder uses lots of data, including business data, to find results.
There is the Places API which can find locations based on type/class, but it may not work for business names. Documentation

Google Maps Geocoding API not returning all results

I was typing "macys" as the search item in here (google maps website) which gives me around 30 to 40 results marked on the map.
Where as when I use their API with query term "macys" then it returns only 2 to 3 results. I am using the following api:
http://maps.googleapis.com/maps/api/geocode/json?address=macys&sensor=false
I am possibly using the wrong API because it says as 'address' in the query parameter. Which API should I be using for getting all macys locations in the US / World?
I want it to return all the lat and lng objects as if its done in their own website (google maps website). If they have not exposed the API then is there a way around?
You should use the Places API:
https://developers.google.com/places/documentation/
Geocoding is not designed to return POIs, it might return some, but you should not depend on it.

Google Maps reverse geocoding returns shorter name

I am using reverse geocoding in Google Maps to get an address from a LatLng position.
However, the formatted address (formatted_address) returned in the result is shorter than the address that I get from using an autocomplete for the same point.
How can I get the same (longer) description using reverse geocoding?
I have a similar problem/request posted at: Google Maps Address Components Geocoding vs Places API - Short vs Long Name
For now, if you take the resulting formatted_address from the geocoder and pass it into a query for the new Places API, get the details for the resulting place.reference, and lastly grab the formatted_address from that response, you'll get a long form address.
Not very clean (hence my feature request at gmaps-api issue list), but it should work for now.
Alex