Reputation: 2040
I am working with a college to develop their campus iOS app. One of the app's features is the ability to determine which of the campus bus routes are most applicable to getting to a destination (as well as a listing of when the bus arrives, etc).
If I have sets of long/lat data representing the stops of a route, what is the easiest way to determine the closest route to a long/lat destination point? I have over 10 roues to consider.
Upvotes: 2
Views: 1560
Reputation: 7716
If you want to determine the closest point to a route, you can use the Distance to a Ray or Segment formula using a lat-lng as the reference point.
There is another option, if you are using a Google Map, because the Terms of Service require that the service be used in the context of a Google Map; you may want to consider the Google Maps Distance Matrix Servicedev-guide. The service allows you to submit a request with an origins
property, which must be an array of google.maps.LatLng
starting points and a destinations
property, which must be an array of google.maps.LatLng
ending points. The DistanceMatrixService
api-doc also allows you to define a TravelMode
api-doc, which may be one of: BICYCLING
, DRIVING
, or WALKING
. It has the advantage over simple distance calculation, because it accounts for the natural activity of traveling from one point to another using the existing network of streets.
Upvotes: 2