I am trying to show directions between 2 'establishment' search results from the Places API, but what is the best way to pass these locations into directions?

When I use the Places library and get the search results, it seems like the best way to pass the location to directions is to use the place[0].geometry.location, which gives a longitude and latitude of the result.

However, with just the longitude and latitude of the place, directions geocodes this into an address and returns results with approximate addresses, whereas I would like it to show the establishment name from Places instead.

For example, after Places return the result for SF MOMA, I would like directions to show directions from somewhere like "San Francisco Museum of Modern Art" instead of "150 3rd Street, San Francisco, CA 94103, USA", which is indescriptive of the location.

Using place[0].name as the location for directions is inaccurate too.

Thanks!! Cody

有帮助吗?

解决方案

place[0].name worked for me, but you can also append the address to the name:

[place[0].name, place[0].vicinity].join(' ');

Example Directions query

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top