Search code examples
iosmapboxmapbox-gl-jsmapbox-ios

StepMilestone | Milestone Listener | Mapbox iOS equivalent


In Mapbox Android SDK, we can able to set/customize the StepMilestone ie we can able to get callbacks before reaching Maneuver of the current step.

Is there any equivalent options available in iOS Mapbox sdk for listening the StepMilestone progress?


Solution

  • Currently on iOS there isn't a direct equivalent, so this is not nearly as straightforward as it is on Android. (disclaimer: I currently work for Mapbox)

    The best way to do this on iOS would be to use turf-swift's LineString.distance(from:to:)​ (which is bundled in the Navigation SDK) to find the closest coordinate on the route based on a given POI.

    Then you can respond to NotificationName.routeControllerProgressDidChange by comparing that distance to RouteProgress.distanceTraveled. If the user has crossed you specified threshold, create a SpokenInstruction and tell the NavigationViewController’s voiceController to speak(_:) it. You can see a somewhat similar example of this last piece in this example: https://docs.mapbox.com/ios/navigation/examples/custom-voice-controller/

    I hope that helps.