3

As per the documentation, we retrieve the distance between a set of origins and destinations in the following manner (Server API).

https://maps.googleapis.com/maps/api/distancematrix/json?origins=Washington%20DC&destinations=New%20York&mode=walking&key=

Instead of passing place names, it would be better if we pass the place_id as the origin or destination. This would give more accurate results. Is it possible ?

For eg. Is it possible to perform an API call like:

https://maps.googleapis.com/maps/api/distancematrix/json?origins=<place_id>&destinations=<place_id>&mode=walking&key=

???

Thankyou

user3506
  • 31
  • 1
  • 3
  • Just address or coordinates. You can get the coordinates requesting details from [Places](https://developers.google.com/maps/documentation/javascript/places#place_details) and them using coordinates as request parameter – Bruno Ribeiro Jul 01 '15 at 23:17
  • @BrunoCésar, Since place_id is a unique identifier, shouldn't it be a universal lookup for every place. – user3506 Jul 01 '15 at 23:29

2 Answers2

6

There are no ways to let google use place_id as origins, or destinations in google maps direction API.

So the only way for you to do this is to get the lat/lng or address from the place_id first. You can do it by:
1) Reverse Geocoding: https://developers.google.com/maps/documentation/geocoding/

https://maps.googleapis.com/maps/api/geocode/json?place_id=ChIJ2eUgeAK6j4ARbn5u_wAGqWA&key=MYKEY

2) Place Details: https://developers.google.com/places/webservice/details

https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJ2eUgeAK6j4ARbn5u_wAGqWA&key=MYKEY

UPDATE

Now you can apply place IDs as origins and destinations in Distance Matrix API.

If you supply a place ID, you must prefix it with place_id:. You can only specify a place ID if the request includes an API key or a Google Maps APIs Premium Plan client ID.

Please refer to documentation for further details:

https://developers.google.com/maps/documentation/distance-matrix/intro#RequestParameters

xomena
  • 31,125
  • 6
  • 88
  • 117
kaho
  • 4,746
  • 1
  • 16
  • 24
3

You can use origin=place_id:<place id> instead of origin="<address>" For more information please refer the link.

abpatil
  • 916
  • 16
  • 20