3

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
    Just calculate the distance to the waypoints. – greenapps Feb 06 '18 at 23:17
  • Is it the "mapbox" way to do this or do you provide me a workaround/solution because it's not possible to do this with milestones or any other things in the navigation SDK ? – Sébastien STOLZ Feb 07 '18 at 08:35
  • Why would you let do those things anybody else where it is so simple to calculate distances yourself? Code is all around on internet. I dont know anythingh of mapbox. – greenapps Feb 07 '18 at 08:43
  • Yes you're right but mapbox SDK provide also a "time remaining" event with the "distance remaining" (https://www.mapbox.com/android-docs/navigation/overview/milestones/), and depending of the results of my tests I will perhaps switch to time remaining instead of distance. I think I will give a shot to custom implementation of distance and dig the SDK if I want to switch to time. – Sébastien STOLZ Feb 07 '18 at 09:57
  • Hi Sébastien, did you by any chance remember this was solved? I'm currently figuring out how to do the same but Mapbox docs are scarce on this. – zzantares Feb 17 '20 at 20:43
  • @zzantares have you figure out problem? – Dinesh Nov 24 '21 at 09:21
  • @Dinesh I barely recall now, but in the end for my use case it made more sense to send the device location to the back-end, and there I would compute the distance to the destination using a geojson library (or you can do the math yourself), when the distance was near enough the back-end sent a push notification to the device so that the app knows that the back-end knows the destination was reached, and I could react on that event on the android app. – zzantares Nov 24 '21 at 21:05
  • @zzantares yeah, thanks for the response but that's a little bit tricky, as any solution from Mapbox itself? – Dinesh Nov 25 '21 at 07:14
  • @Dinesh then use distanceBetween method from android.location.Location class, in the end Mapbox only gives you the points and you're free to do with them what ever you need, so you're not tied to Mapbox to compute the distance, good luck! – zzantares Nov 25 '21 at 17:41

1 Answers1

0

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

Arno den Hond
  • 627
  • 1
  • 7
  • 24