-2

I think it might be impossible, but I wanted to check with you guys.

The Google Directions API. Is it possible to calculate the route to a larger area, rather than pin-pointing to a Lat and Long?

E.g. Imagine a huge national park.. there are many ways to get there, and many 'entrances'. Is there a way to force Google Directions API to calculate the quickest route to a 'general area' or a custom polygon?

Steviewevie
  • 189
  • 1
  • 13

1 Answers1

1

Not sure what you expect, but usually large places as you described, have a kind of center point that will be used by the API when requesting directions based on its place name.

Depending on the travel mode (walking, driving, etc.) you will see that the directions don't always end at the same exact coordinates. This is particularly true for places like National Parks, etc.

There is no way (yet) to get a place boundaries via the API. This is a long awaited (10 years...) feature request to which you can of course subscribe.

If you can define the area by yourself (as a Polygon for example), you could then take a few points on that shape's borders (ie. North, East, South, West) and use the Distance Matrix API to find out which point is the closest/shortest from your origin location (obviously you could also just save some points around your place instead of a Polygon).

If you need these points to be on a road, (if you need DRIVING directions / if you want to increase your chances to be able to retrieve directions), you could first use the Google Maps Roads API and do a Nearest Road request for each of the defined "entrance" points and use the returned coordinates for your Distance Matrix requests.

Once you find out which of these points is the closest from your origin location, you can request directions to it using the Directions Service and display it on your map.

MrUpsidown
  • 21,592
  • 15
  • 77
  • 131