0

I'm trying to test off route detection in mapbox navigation and it is not working. I've traced through and the OffRouteDetector.isUserOffRouteWith is getting called, but the status.getRouteState() is only ever returning "INITIALIZED" (which is not the expected RouteState.OFFROUTE)

I suspect there's an edge case I'm hitting as I'm using a trip with a start and end that are very far away from my current location. As such, it never "gets going". However, this is a valid scenario in my application (it involves stored routes that are immutable due to public safety concerns).

I've made an issue (that was closed) on github, but for background, it is here

EDIT: Here is some code to get closer to what I'm trying to do. This is from the onCreate of the MainActivity of a default android studio project:

        String jsonRoute = "{\"routes\":[{\"legs\":[{\"steps\":[{\"intersections\":[{\"out\":1,\"entry\":[false,true],\"bearings\":[0,90],\"location\":[-71.45082724993496,43.070903929852619],\"in\":0},{\"out\":1,\"entry\":[false,true],\"bearings\":[27,90],\"location\":[-71.444301000091471,43.023085298378462],\"in\":0}],\"driving_side\":\"right\",\"weight\":7560.0,\"geometry\":\"mbxcqArekhgCoG{B}HmGuHaLaGiT{@mPHs[bJggEUqYiA_KgCcJyKyVyGgJ\",\"maneuver\":{\"bearing_after\":90,\"type\":\"depart\",\"modifier\":\"\",\"bearing_before\":0,\"location\":[-71.45082724993496,43.070903929852619],\"instruction\":\"Travel on NO NAME\"},\"duration\":0.0,\"distance\":547.06000000000006,\"name\":\"NO NAME\",\"mode\":\"driving\",\"voiceInstructions\":[{\"distanceAlongGeometry\":547.06000000000006,\"announcement\":\"Travel on NO NAME, then Turn right onto US-3 [NH-28], [HOOKSETT RD]\",\"ssmlAnnouncement\":\"<speak><amazon:effect name=\\\"drc\\\"><prosody rate=\\\"1.08\\\">Travel on NO NAME, then Turn right onto US-3 [NH-28], [HOOKSETT RD]</prosody></amazon:effect></speak>\"},{\"distanceAlongGeometry\":90.0,\"announcement\":\"Turn right onto US-3 [NH-28], [HOOKSETT RD]\",\"ssmlAnnouncement\":\"<speak><amazon:effect name=\\\"drc\\\"><prosody rate=\\\"1.08\\\">Turn right onto US-3 [NH-28], [HOOKSETT RD]</prosody></amazon:effect></speak>\"}],\"bannerInstructions\":[{\"distanceAlongGeometry\":547.06000000000006,\"primary\":{\"text\":\"US-3 / NH-28 / HOOKSETT RD\",\"type\":\"turn\",\"modifier\":\"right\",\"degrees\":0,\"components\":[{\"type\":\"text\",\"text\":\"US-3\",\"delimiter\":false},{\"type\":\"delimiter\",\"text\":\"/\",\"delimiter\":true},{\"type\":\"text\",\"text\":\"NH-28\",\"delimiter\":false},{\"type\":\"delimiter\",\"text\":\"/\",\"delimiter\":true},{\"type\":\"text\",\"text\":\"HOOKSETT RD\",\"delimiter\":false}]},\"secondary\":null}]},{\"intersections\":[{\"out\":1,\"entry\":[false,true],\"bearings\":[27,90],\"location\":[-71.444301000091471,43.023085298378462],\"in\":0},{\"out\":1,\"entry\":[false,true],\"bearings\":[197,211],\"location\":[-71.444535949177578,43.0230007289918],\"in\":0}],\"driving_side\":\"right\",\"weight\":6677.0,\"geometry\":\"}yycqAzk_hgCpLqOrNaNhTqMlfAsm@|\\\\eSb`@{ZvoBinBrKkJ~t@cg@r\\\\wQvrHimDv}Asz@xz@gd@n\\\\}PrpAil@prCmvAhgBa_A|m@qZvPcJlx@{]l_@iN~GuC~VgFpO}@bGEd[zBvo@jJ|cAeHvoCsWn]eJzuAkf@p`@aQ|sBypAzSkKrMsExPmDlUgAzNx@~OrC|NjFvaBp|@h]dMtmAbZb`Bv`@h\\\\fOxpCvtB|SjSrKxNjO`\\\\~FtNzKp_@xI|NrI`JvlHdmG\",\"maneuver\":{\"bearing_after\":90,\"type\":\"turn\",\"modifier\":\"right\",\"bearing_before\":27,\"location\":[-71.444301000091471,43.023085298378462],\"instruction\":\"Turn right onto US-3 [NH-28], [HOOKSETT RD]\"},\"duration\":186.0,\"distance\":5921.12,\"name\":\"US-3\",\"mode\":\"driving\",\"voiceInstructions\":[{\"distanceAlongGeometry\":5792.4000000000005,\"announcement\":\"In 3.6miles, I-93 SB ON RAMP\",\"ssmlAnnouncement\":\"<speak><amazon:effect name=\\\"drc\\\"><prosody rate=\\\"1.08\\\">In 3.6miles, I-93 SB ON RAMP</prosody></amazon:effect></speak>\"},{\"distanceAlongGeometry\":90.0,\"announcement\":\"I-93 SB ON RAMP\",\"ssmlAnnouncement\":\"<speak><amazon:effect name=\\\"drc\\\"><prosody rate=\\\"1.08\\\">I-93 SB ON RAMP</prosody></amazon:effect></speak>\"}],\"bannerInstructions\":[{\"distanceAlongGeometry\":5921.12,\"primary\":{\"text\":\"I-93 NB EXIT 9 OFF RAMP\",\"type\":\"turn\",\"modifier\":\"straight\",\"degrees\":0,\"components\":[{\"type\":\"text\",\"text\":\"I-93 NB EXIT 9 OFF RAMP\",\"delimiter\":false}]},\"secondary\":null}]},{\"intersections\":[{\"out\":1,\"entry\":[false,true],\"bearings\":[197,211],\"location\":[-71.444535949177578,43.0230007289918],\"in\":0},{\"out\":1,\"entry\":[false,true],\"bearings\":[126,135],\"location\":[-71.2864750743811,42.81703500887609],\"in\":0}],\"driving_side\":\"right\",\"weight\":838.0,\"geometry\":\"im|`qA~srggCfe@`l@lGlLtDpZ]~LoDpReEfJoHbIw`Ajt@mPlEiIQyNcGuFkG_HmUq@}QV{EfB_MfAqDpIaOxtAetA\",\"maneuver\":{\"bearing_after\":211,\"type\":\"turn\",\"modifier\":\"straight\",\"bearing_before\":197,\"location\":[-71.444535949177578,43.0230007289918],\"instruction\":\"I-93 SB ON RAMP\"},\"duration\":23.0,\"distance\":788.41,\"name\":\"I-93 NB EXIT 9 OFF RAMP\",\"mode\":\"driving\",\"voiceInstructions\":[{\"distanceAlongGeometry\":643.6,\"announcement\":\"In 0.4miles, Continue straight on I-93 SOUTH\",\"ssmlAnnouncement\":\"<speak><amazon:effect name=\\\"drc\\\"><prosody rate=\\\"1.08\\\">In 0.4miles, Continue straight on I-93 SOUTH</prosody></amazon:effect></speak>\"},{\"distanceAlongGeometry\":90.0,\"announcement\":\"Continue straight on I-93 SOUTH\",\"ssmlAnnouncement\":\"<speak><amazon:effect name=\\\"drc\\\"><prosody rate=\\\"1.08\\\">Continue straight on I-93 SOUTH</prosody></amazon:effect></speak>\"}],\"bannerInstructions\":[{\"distanceAlongGeometry\":788.41,\"primary\":{\"text\":\"I-93 SOUTH\",\"type\":\"turn\",\"modifier\":\"straight\",\"degrees\":0,\"components\":[{\"type\":\"text\",\"text\":\"I-93 SOUTH\",\"delimiter\":false}]},\"secondary\":null}]},{\"intersections\":[{\"out\":1,\"entry\":[false,true],\"bearings\":[126,135],\"location\":[-71.2864750743811,42.81703500887609],\"in\":0},{\"out\":1,\"entry\":[false,true],\"bearings\":[136,140],\"location\":[-71.275545391600389,42.809408142172572],\"in\":0}],\"driving_side\":\"right\",\"weight\":27322.0,\"geometry\":\"_h|`qAtbsggCbE}C~FgGbxK_zIloDguC|i@w`@j\\\\mSn\\\\}Pf]aOf`AmYx`@aIjdGmz@nrCqb@rb@}Irs@uSzo@s^x]{ZvZ}_@hO}TzV}f@lMy\\\\tJsZfu@auCxdA}gE`W_z@b_@}zApO_h@pHsRnIoQ`JiQbJ{NpXq]`[sXn\\\\cT`_@eO|c@mMxp@kN|]gIpiAyVho@oLjcBeR`wBmIb{DiQpq@cFl~BuZvmDcf@|a@eF|u@sGdQk@xPgAvc@w@|uDaHz}CsIv{@}Gvr@kR`k@sWvpB{eAjfAij@`o@cZf}@}XvkB{_@ft@_Qtp@qYbXoRzZiZbXm^x`Ak{A`^mk@na@_k@|m@k~@zDsEvF}HzYm[~KqLlLsKrPoLlzAajAx]yZz\\\\c_@xN}Q~MyS~s@{hAzd@ov@hrKetP~n@caA`NyS|J_M|\\\\gb@l\\\\{\\\\n^k[z_@gYfr@ua@bo@sWr_@_Od|Aif@lrAoc@~cCsw@blA}`@riBql@tk@}T`_A_e@pyDgaCvpUauNhlAyp@b}B{fAv`@}TlwH}zCzjK}dEphAki@dj@{[viAuu@l}@ut@xgAifAfpIg~JjcFwbGhSgTh_@s\\\\r]yVfb@wVld@yRxWsJlM{D`tW}kHhvBwo@nl@qXnr@cc@|pAqhAto@g{@tj@k_AlWyi@lUeh@~^sgAr\\\\usAl`@abC~]qxBvU_wAvYoyAnJqb@fT}v@j]ghAd]q{@xSqe@ls@{tAlWoc@dTy[hv@qeAd]o`@nm@{l@r}UouSt}@u{@~z@w_AdcDkfEtmBkfCvZy_@p^sa@l^u]d_@y[haAup@vp@q\\\\|cAgf@|wA_n@xi@w\\\\xm@sYtlHcgDdnAek@nvAko@v~@ic@lx@of@\",\"maneuver\":{\"bearing_after\":135,\"type\":\"turn\",\"modifier\":\"straight\",\"bearing_before\":126,\"location\":[-71.2864750743811,42.81703500887609],\"instruction\":\"Continue straight on I-93 SOUTH\"},\"duration\":803.0,\"distance\":27320.82,\"name\":\"I-93 SOUTH\",\"mode\":\"driving\",\"voiceInstructions\":[{\"distanceAlongGeometry\":25744.0,\"announcement\":\"In 16miles, I-93 SB EXIT 3 OFF RAMP TO NH-111\",\"ssmlAnnouncement\":\"<speak><amazon:effect name=\\\"drc\\\"><prosody rate=\\\"1.08\\\">In 16miles, I-93 SB EXIT 3 OFF RAMP TO NH-111</prosody></amazon:effect></speak>\"},{\"distanceAlongGeometry\":90.0,\"announcement\":\"I-93 SB EXIT 3 OFF RAMP TO NH-111\",\"ssmlAnnouncement\":\"<speak><amazon:effect name=\\\"drc\\\"><prosody rate=\\\"1.08\\\">I-93 SB EXIT 3 OFF RAMP TO NH-111</prosody></amazon:effect></speak>\"}],\"bannerInstructions\":[]},{\"intersections\":[{\"out\":1,\"entry\":[false,true],\"bearings\":[136,140],\"location\":[-71.275545391600389,42.809408142172572],\"in\":0},{\"out\":1,\"entry\":[false,true],\"bearings\":[90,0],\"location\":[-71.408027396106363,42.771592398141067],\"in\":0}],\"driving_side\":\"right\",\"weight\":1481.0,\"geometry\":\"c_jtpAzk~}fC`o@c]br@}o@~f@eo@n\\\\uh@`e@{_AdZyw@dW_}@lnAcnEz^yrAnBaHhM_\\\\lJgPfKmN|O{KbIgCzQ_D`FpAxC|CjBjKpCn`@\",\"maneuver\":{\"bearing_after\":140,\"type\":\"turn\",\"modifier\":\"straight\",\"bearing_before\":136,\"location\":[-71.275545391600389,42.809408142172572],\"instruction\":\"I-93 SB EXIT 3 OFF RAMP TO NH-111\"},\"duration\":41.0,\"distance\":1383.74,\"name\":\"I-93 I93 S OFF RAMP\",\"mode\":\"driving\",\"voiceInstructions\":[{\"distanceAlongGeometry\":1287.2,\"announcement\":\"In 0.8miles, Merge onto NH-111 [INDIAN ROCK RD]\",\"ssmlAnnouncement\":\"<speak><amazon:effect name=\\\"drc\\\"><prosody rate=\\\"1.08\\\">In 0.8miles, Merge onto NH-111 [INDIAN ROCK RD]</prosody></amazon:effect></speak>\"},{\"distanceAlongGeometry\":90.0,\"announcement\":\"Merge onto NH-111 [INDIAN ROCK RD]\",\"ssmlAnnouncement\":\"<speak><amazon:effect name=\\\"drc\\\"><prosody rate=\\\"1.08\\\">Merge onto NH-111 [INDIAN ROCK RD]</prosody></amazon:effect></speak>\"}],\"bannerInstructions\":[{\"distanceAlongGeometry\":1383.74,\"primary\":{\"text\":\"NH-111 / INDIAN ROCK RD\",\"type\":\"turn\",\"modifier\":\"straight\",\"degrees\":0,\"components\":[{\"type\":\"text\",\"text\":\"NH-111\",\"delimiter\":false},{\"type\":\"delimiter\",\"text\":\"/\",\"delimiter\":true},{\"type\":\"text\",\"text\":\"INDIAN ROCK RD\",\"delimiter\":false}]},\"secondary\":null}]},{\"intersections\":[{\"out\":1,\"entry\":[false,true],\"bearings\":[90,0],\"location\":[-71.408027396106363,42.771592398141067],\"in\":0}],\"driving_side\":\"right\",\"weight\":20698.0,\"geometry\":\"mb{spAx`i}fCLhi@~CvvAzj@laHlN|u@dyAnwFpIh\\\\tLvo@jM`gAjJ~|Afb@`gHhDfn@rDz`@rH`g@zObt@~Vns@~`@pu@lv@pdAxbBjuBxUj^vIfUtOhc@zSzw@vC`SnIt}@v@lfAuBbj@gDb`@urAlhNcWtlB}dA`rGiuBjjM_UxxA_OtcBuCfl@iB|bACxu@pCdpAl_AfnMzNjoBzIxu@hJfm@`UncApT~p@dc@fbAph@n{@ds@nfAhuBphDhtAnuBthC`eEr{AnnCfkAvwBdwBvvDz[bf@pqA~bBdwB|rCpe@~o@vg@py@f_@zx@h~G~vPhTti@ba@xoAvMnj@ppAbgG~\\\\p|At]zxAt]`pA`f@n}Ap\\\\p`ArdBduEro@|dB`cChrG\",\"maneuver\":{\"bearing_after\":0,\"type\":\"arrive\",\"modifier\":\"\",\"bearing_before\":90,\"location\":[-71.408027396106363,42.771592398141067],\"instruction\":\"Merge onto NH-111 [INDIAN ROCK RD]\"},\"duration\":503.0,\"distance\":12421.48,\"name\":\"NH-111\",\"mode\":\"driving\",\"voiceInstructions\":[{\"distanceAlongGeometry\":12389.300000000001,\"announcement\":\"In 7.7miles, Arrive at destination.\",\"ssmlAnnouncement\":\"<speak><amazon:effect name=\\\"drc\\\"><prosody rate=\\\"1.08\\\">In 7.7miles, Arrive at destination.</prosody></amazon:effect></speak>\"},{\"distanceAlongGeometry\":90.0,\"announcement\":\"Arrive at destination.\",\"ssmlAnnouncement\":\"<speak><amazon:effect name=\\\"drc\\\"><prosody rate=\\\"1.08\\\">Arrive at destination.</prosody></amazon:effect></speak>\"}],\"bannerInstructions\":[{\"distanceAlongGeometry\":12421.48,\"primary\":{\"text\":\"NH-111 / CENTRAL ST\",\"type\":\"arrive\",\"modifier\":\"\",\"degrees\":0,\"components\":[{\"type\":\"text\",\"text\":\"NH-111\",\"delimiter\":false},{\"type\":\"delimiter\",\"text\":\"/\",\"delimiter\":true},{\"type\":\"text\",\"text\":\"CENTRAL ST\",\"delimiter\":false}]},\"secondary\":null}]}],\"summary\":\"NO NAME, 1.4mi S of Hooksett - NH-111, 3.1mi NE of Nashua\",\"duration\":1556.0,\"distance\":48366.5390625,\"weight\":66578.0}],\"geometry\":\"mbxcqArekhgCoG{BcOoNyEyKwDgTQif@bJggEUqYiA_KcI{UwNiVdUkX~EgEv{Ae|@`w@yh@`aAu~@tt@{t@rKkJ~t@cg@vr@m^b|BceAze@uTzV{KlhDydB|`Aei@nVyLnuAyp@huHowDhWcN~VqLzt@mZxZeKdP}CtWcAd[zBta@lHvU|@~kEy`@ni@mO|bBin@vPaJ|_Awl@tQcL`WwOzSkKrMsExPmDbPw@hDOzNx@rWjFj_@dQlq@v_@bh@vVb{Ax_@b`Bv`@h\\\\fOzaCbhBr[rXzRdVpIjPxRnh@zElQlOvUxgH`iG|HjGhk@xs@rC`KlBdTkAlT}EfQ{FtIueA|x@mPlEcToCuKqK{EiNwBuRXgLfB_MtDmJfKoNjyAiwAjn@wh@j|JyaIf`DmhC|i@w`@j\\\\mSn\\\\}Pf]aOd_@yLhOyEvOyDx`@aIr\\\\wErlKq|AzdAiYzo@s^x]{ZhLaNvf@it@nV_k@tXs|@zsA}kF~]i{A`W_z@vWofAnNmh@lG_SpHsRnIoQ`JiQdWs_@nKyL`[sXfMwIfNkIbOoG|NuF|c@mMzx@_Q`iA_Wp}@sQnlBoTlZe@nxHk_@ffAiK~hAuPvmDcf@zs@eI~c@sD~b@sBvrHqMtXeCzhBsJvr@kRlcG}{CxO_Hr^_Mr]}Jt_@kIbpBoa@~^_Ln_@mQtK}Gth@_f@|o@_`A`hAgfBrvAorBhn@mq@lLsKt|@_q@jn@qe@hv@ct@~J}LrnHgiLvuE}kH`~@}uAzh@gp@l\\\\{\\\\n^k[z_@gYfr@ua@bo@sWr_@_OroDyjAv{HcgCtk@}T`_A_e@|hOcjJl_D{nBd_CswA~a@oXlWwNhe@mZtn@e^flAsm@vb@mSnkAkl@dhMccFh`HyqCxz@cd@zdAcq@`uAifAv}Ae~AthOirQhi@al@h_@s\\\\r]yVfb@wVld@yRxWsJriRskFx_AaWtdDu~@thAe^nl@qX`i@g\\\\|a@yZlw@ss@vWe\\\\zr@}eAd_@ws@pl@exAfj@cpBd[uiBl[qqBx`@caCnH}`@rTaeAxTa}@rY{`Ap\\\\g~@zUkj@lPg]zj@mfAlWoc@fl@s{@`m@qv@z|@q}@feP_oNluA_nA|`BovAt}@u{@~z@w_Axc@{j@j~BozCd}A}rBnOmRtE{Frs@qz@ln@uk@dOyMhaAup@tuBycA|wA_n@xi@w\\\\xmBg|@~dNcqGrWoO|MgJ`o@c]br@}o@zu@ecAn^}o@db@c`AlZ}~@jxAoiFjb@{{AdCsHbIkRrDgG`QmWhKyHvRmHzL{A`FpAxC|CjBjKpCn`@Lhi@~CvvA`b@foFxGdq@lN|u@lv@`xCrZjjAtPjp@nE`VjPpfApNdwBfb@`gH|IbpA~CzWlMdo@`FbSzM`a@bHlQpSna@~]dj@nhAtxAd_AbjAxUj^lDvI~Txn@zSzw@`H|f@xFfbAPx_@cChx@kTjbCqbAdfKqg@zoDyV`|Aab@tgCox@p`Fsp@xzDyZ|pBeGnl@oKlcBuBzyAhAbpA`F~eAzz@dgLzNjoBzIxu@hJfm@`UncApT~p@dc@fbAjsG|eKhlCdgEp[xj@~iCjyEziCxsEz[bf@||@~iAjeDhlEfTpZn_@rn@f_@zx@jmH`uQlM|\\\\|Xn~@zW~iAj`@`lBjXppA|z@bzDbk@jvBhs@v{B|tBnxFzmA~eDbOr`@ds@djBlPvb@fz@~~Bgi@e|A\",\"duration\":1556.0,\"distance\":48366.54,\"weight\":66578.0,\"weight_name\":\"routability\",\"voiceLocale\":\"en-US\"}],\"waypoints\":[{\"name\":\"NO NAME, 1.4mi S of Hooksett\",\"location\":[-71.45688,43.07003]},{\"name\":\"NH-111, 3.1mi NE of Nashua\",\"location\":[-71.40803,42.77159]}],\"code\":\"Ok\",\"uuid\":\"cjqsavmw70crz3po391gqh3mp\"}";
        DirectionsResponse directions = DirectionsResponse.fromJson(jsonRoute);

        DirectionsRoute route = directions.routes().get(0);

        ArrayList<Point> wpPoints = new ArrayList<Point>();
        for(DirectionsWaypoint w : directions.waypoints())
            wpPoints.add((w.location()));

        RouteOptions newRO = RouteOptions.builder()
                .profile(DirectionsCriteria.PROFILE_DRIVING)
                .coordinates(wpPoints)
                .user("mapbox")
                .geometries(DirectionsCriteria.GEOMETRY_POLYLINE6)
                .accessToken(accessToken)
                .requestUuid(directions.uuid())
                .baseUrl("https://api.mapbox.com")

                .waypointNames("")
                .continueStraight(true)
                .annotations("distance")
                .approaches("")
                .bearings(";")
                .alternatives(false)
                .language("en")
                .radiuses("")
                .voiceInstructions(true)
                .bannerInstructions(true)
                .roundaboutExits(true)
                .overview("full")
                .steps(true)
                .voiceUnits("imperial")
                .exclude("")
                .waypointTargets("")
                .build();

        route = route.toBuilder().routeOptions(newRO).build();

        boolean simulateRoute = false;

// Create a NavigationLauncherOptions object to package everything together
        NavigationLauncherOptions options = NavigationLauncherOptions.builder()
                .directionsRoute(route)
                .shouldSimulateRoute(simulateRoute)
                .build();

// Call this method with Context from within an Activity
        NavigationLauncher.startNavigation(this, options);
Troy Berg
  • 201
  • 2
  • 10

2 Answers2

1

@Troy Berg Let me take a quick second to explain how the route following code works internally when a fresh route is loaded.

Upon loading a new route, if the route json is valid, the MapboxNavigator will start in the INITIALIZED state. From there it will attempt to gain confidence that the GPS locations being passed in are actually the location where the user is. To establish this trust it needs to receive at least a few location updates and those must be consequtively coherent in both time and space. While it's in the process of establishing this trust it will report the INITIALIZED state.

Once trust of the users current stream of location updates has been established, the MapboxNavigator will attempt to measure the user's progress along the currently loaded route. If the user's location is found to be unreasonably far from the route itself, the state is flipped to the OFFROUTE state.

If the user's current location is within a reasonable distance from the currently loaded route but not close enough to be considered on-route (TRACKING) we will continue to return the INITIALIZED state and wait for the user to make their way to the route. We call this corraling. Corraling allows a user, in his/her driveway or a store's parking lot for example, to load up a route and not immediately get marked as OFFROUTE. While corraling, if the user continually makes progress away from the route they will eventually be marked OFFROUTE.

Kevin Kreiser
  • 594
  • 5
  • 11
  • Thanks Kevin! Ok, my sample trip is in New Hampshire somewhere. I am in TX; so, I should think that I wouldn't be in that "close, but not quite tracking" state (which would yield the "INITIALIZED" state). Granted, this is contrived, but it helps determine where I am in the state transitions). So, it would seem, like Dan said, I'm in the "no confidence of location" state, still. This is on a physical device, btw. I walked down to the end of my street and back and, while the locator on the map tracked my position, I still did not get my "OFFROUTE" state. Am I *too* far from the route? – Troy Berg Jan 18 '19 at 13:31
  • Also, is there a way to get the native Navigator's "estimated distance from route"? On states, would it make sense to go ahead and formalize your "not quite tracking" state as a "CORRALING" state? – Troy Berg Jan 18 '19 at 13:32
  • Yep, after the GPS becomes trusted it should flip from `INITIALIZED` to `OFFROUTE`. We have seen it stick in the *no confidence* when GPS locations weren't being pushed to the API at regular intervals. We ended up working around this by building a alternate location engine. Could you give that a try? See this issue for more info: https://github.com/mapbox/mapbox-navigation-android/issues/1469#issuecomment-442450591 As for adding more states, we sure could do that. At this point its a matter of balancing simplicity of the happy path vs complexity useful in debugging the not happy path. – Kevin Kreiser Jan 18 '19 at 13:45
  • You're talking about the FusedLocationEngine, correct? I get a Page Not found on that (and searching in google, any links also take me to a page not found). – Troy Berg Jan 18 '19 at 14:20
  • As of `v0.27.0` https://github.com/mapbox/mapbox-events-android/blob/master/liblocation/src/main/java/com/mapbox/android/core/location/GoogleLocationEngineImpl.java is returned if you add the Location GMS dependency and get the best location engine available e.g. https://github.com/mapbox/mapbox-navigation-android/blob/master/app/src/main/java/com/mapbox/services/android/navigation/testapp/activity/navigationui/ComponentNavigationActivity.java#L327 `FusedLocationEngine` was removed in https://github.com/mapbox/mapbox-navigation-android/pull/1615/files#diff-9a3f7988ba9a00ab405d48c1d94d73b1 – Guardiola31337 Jan 21 '19 at 17:11
0

I went ahead and just set my own offRouteEngine. I kept the original, though, and reference that in mine. The code is:

       MapboxNavigation mbn = navigationView.retrieveMapboxNavigation();
        orEngine = (OffRouteDetector)mbn.getOffRouteEngine();
        mbn.setOffRouteEngine(new OffRouteDetector() {
            @Override
            public boolean isUserOffRoute(Location location, RouteProgress routeProgress, MapboxNavigationOptions options) {
                Boolean isOffRoute = orEngine.isUserOffRoute(location, routeProgress, options);
                // User will never be off-route
                return isOffRoute;
            }
            public boolean isUserOffRouteWith(NavigationStatus status) {
                return orEngine.isUserOffRouteWith(status) || status.getRouteState() == RouteState.INITIALIZED;
            }
        });

In that code, I'm counting the "INITIALIZED" state as off route. As I do not reroute but, instead, show a message, I think this should work out ok.

Please let me know if you see any issues with this method and thanks for your help!

Troy Berg
  • 201
  • 2
  • 10