Is there a way to determine if a particular address is along a route within x miles? Is there support for this in the Google maps API?
I have a database of addresses and I am trying to figure out which locations lie along a given route as determined by the Google Maps API.
You can set the getPolyline option, on the GDirectionsOptions optional parameter, to the GDirections load request. This will get you the polyline data for the route.
Once you have this data you can iterate over each point in the polyline and determine the distance to each of your own datapoints (you can use the GLatLng distanceFrom method to calculate the distance).
Once you have the shortest distance to your route for each of your data points, you can and work out, based on some tolerance, if the point lies on the route.
Edit:
Although it is fine to call the GLatLng distanceFrom method repeatedly (it is just a utility method to get the distance between two points), I realized my answer simplifies the problem. To get an accurate distance from the route, you will need to determine the distance from the polyline between the closest two points (not just the distance from each point).
Bill Chadwick has "Distance of Point to Polyline or Polygon" code at the bottom of this page, which could prove useful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With