How to detect I'm near a waypoint

841 Views Asked by At

I want to make a navigation application on Android (Kotlin) using the mapbox-android SDK. I need to create a route with specific waypoints and want to know when I am near one of those waypoints (200m before for example). I already managed to display a map with my waypoints with the NavigationRoute object and launch a turn-by-turn navigation using the NavigationLauncher object. Still, I don't have a clue how to know when I'm getting near a waypoint. I've read things about milestones event listener (step or route), RouteProgress (leg or route), but I don't know if it's the right approach to do this.

I tried to declare a milestone with a STEP_DISTANCE_REMAINING_METERS and add a MilestoneEventListener but nothing fire up in my logs. Like I said, I don't even know if it's the right way to do this.

val milestone = RouteMilestone.Builder()
        .setIdentifier(100)
        .setTrigger(Trigger.all(
                Trigger.lt(TriggerProperty.STEP_DISTANCE_REMAINING_METERS, 200)
        ))
        .build()

navigation = MapboxNavigation(this@MainActivity, Mapbox.getAccessToken())
navigation.addMilestone(milestone)

navigation.addMilestoneEventListener { _, _, milestone ->
    Log.d(TAG, "milestone triggered: " + milestone.instruction)
}

navigationMapRoute = NavigationMapRoute(navigation, mapView, map, R.style.NavigationMapRoute)
navigationMapRoute!!.addRoute(currentRoute)

I'm using those versions of mapbox SDK

  • mapbox-android-sdk:5.3.2
  • mapbox-android-navigation:0.9.0
  • mapbox-android-navigation-ui:0.9.0
1

There are 1 best solutions below

0
Arno den Hond On

If you know the location of your waypoints you could just use Location Manager's Proximity Alert