3

I have 2 Place IDs I've obtained via the Google Places API, and want to display a link to the Google Maps app for directions between those 2 places.

I see that it's possible to do this with 2 addresses based on the answer at Current Location - Google Maps - Link to Directions using the saddr and daddr query parameters

I also see that it's possible to link to a map with a place ID by prefixing place_id:... in the q query parameter from this answer at Getting Google Maps link from place_id

Is there a way to have a directions link with the Google place_id? I tried a URL like: https://www.google.com/maps/dir/place_id:ChIJp4JiUCNP0xQR1JaSjpW_Hms/place_id:ChIJp4JiUCNP0xQR1JaSjpW_Hms and it doesn't seem to work

xomena
  • 31,125
  • 6
  • 88
  • 117
phsource
  • 2,326
  • 21
  • 32
  • Have you tried the [Embed API directions mode](https://developers.google.com/maps/documentation/embed/guide#directions_mode)? – geocodezip Aug 29 '19 at 21:41
  • Directly going to the URL `https://www.google.com/maps/embed/v1/directions?key=MY_API_KEY&origin=Oslo+Norway&destination=Telemark+Norway&avoid=tolls|highways` gives the error: "The Google Maps Embed API must be used in an iframe." – phsource Aug 29 '19 at 23:26

1 Answers1

5

In order to open Google Maps directions mode with place IDs you have to use Google Maps URLs. The Google Maps URLs in directions mode support parameters origin_place_id and destination_place_id.

Create the following URL for example (note that origin and destination parameters are also mandatory as per documentation)

https://www.google.com/maps/dir/?api=1&origin=Yukar%C4%B1%20Bah%C3%A7elievler%2C%2070.%20Sk.%2017%2FB%2C%2006490%20%C3%87ankaya%2FAnkara%2C%20Turkey&origin_place_id=ChIJp4JiUCNP0xQR1JaSjpW_Hms&destination=Be%C5%9Fikkaya%2C%202044%2F1.%20Sk.%2C%2006230%20Alt%C4%B1nda%C4%9F%2FAnkara%2C%20Turqu%C3%ADa&destination_place_id=ChIJn-ZptRFT0xQRGUyoJX2s8Wc

Have a look at the documentation for further details.

I hope this helps!

xomena
  • 31,125
  • 6
  • 88
  • 117