I have a route (MKPolyline
derived from an MKRoute
retrieved from Apple's MKDirections
API) and a bunch of points of interest (array of MKAnnotation
s) that are close to the route.
I would like to know how to select the next POI the user is going to meet following the route, in order to present it through a UI.
Two different approaches come to mind, but none of them is really adequate:
The first one would be to mark the POIs as checked each time you get close enough to them, and simply display the first unmarked POI in the array (we'll assume that they are correctly ordered). The problem is that if for a reason or another one of the POIs is not checked, then the app will forever display it instead of displaying the actual next POI coming. This situation can arise e.g. if the user followed a slightly different route than the one suggested, that didn't come close enough to the POI to get it checked; or the user starts the navigation after the first POI; etc.
The second one one would be to select the POI closest to the user (probably also with a marking system to avoid presenting the POI you just checked). But this would only work for routes straight enough: sometimes in mountain zones or other sinuous routes you can get closer to a point that you will actually cross later. I expect this situation to happen actually quite often.
Any idea?