Skip to content

OffRouteDetector throws error for line with two identical points #151

@karussell

Description

@karussell

When using the latest version (main branch) of the android demo against the GraphHopper API I get an error for the last segment of the route:

org.maplibre.geojson.turf.TurfException: Turf nearestPointOnLine requires a List of Points made up of at least 2 coordinates.
 at org.maplibre.geojson.turf.TurfMisc.nearestPointOnLineInternal(TurfMisc.kt:244)
 at org.maplibre.geojson.turf.TurfMisc.nearestPointOnLine(TurfMisc.kt:228)
 at org.maplibre.geojson.turf.TurfMisc.nearestPointOnLine$default(TurfMisc.kt:221)
 at org.maplibre.navigation.core.utils.ToleranceUtils.dynamicOffRouteRadiusTolerance(ToleranceUtils.kt:30)
 at org.maplibre.navigation.core.offroute.OffRouteDetector.createOffRouteRadius(OffRouteDetector.kt:166)
 at org.maplibre.navigation.core.offroute.OffRouteDetector.checkOffRouteRadius(OffRouteDetector.kt:156)
 at org.maplibre.navigation.core.offroute.OffRouteDetector.isUserOffRoute(OffRouteDetector.kt:80)
 at org.maplibre.navigation.core.navigation.NavigationHelper.isUserOffRoute(NavigationHelper.kt:482)
 at org.maplibre.navigation.core.navigation.engine.MapLibreNavigationEngine.determineUserOffRoute(MapLibreNavigationEngine.kt:142)
 at org.maplibre.navigation.core.navigation.engine.MapLibreNavigationEngine.processLocationUpdate(MapLibreNavigationEngine.kt:100)

The problem seems to be that one of the intersections lists contains only a single element, i.e. this code creates a line with just one point.

Complete example response:

{"routes":[{"geometry":"{ebm`BkamcYpMgFbLsEvd@}QmPugA","legs":[{"steps":[{"intersections":[{"location":[13.70423,51.086958],"entry":[true],"bearings":[343],"out":0},{"location":[13.704346,51.086725],"entry":[true,false],"bearings":[163,343],"in":1,"out":0},{"location":[13.704452,51.086515],"entry":[true,false],"bearings":[163,343],"in":1,"out":0}],"driving_side":"right","geometry":"{ebm`BkamcYpMgFbLsEvd@}Q","mode":"driving","maneuver":{"bearing_after":0,"bearing_before":0,"location":[13.70423,51.086958],"modifier":"straight","type":"depart","instruction":"continue onto Leipziger Straße"},"weight":122.1,"duration":13.7,"name":"Leipziger Straße","distance":122.1,"voiceInstructions":[{"distanceAlongGeometry":80.0,"announcement":"turn left onto Jubiläumsstraße, then arrive at destination","ssmlAnnouncement":"<speak><amazon:effect name=\"drc\"><prosody rate=\"1.08\">turn left onto Jubiläumsstraße, then arrive at destination</prosody></amazon:effect></speak>"}],"bannerInstructions":[{"distanceAlongGeometry":122.1,"primary":{"text":"Jubiläumsstraße","components":[{"text":"Jubiläumsstraße","type":"text"}],"type":"turn","modifier":"left"},"secondary":null,"sub":{"text":"Arrive at destination","components":[{"text":"Arrive at destination","type":"text"}],"type":"arrive"}}]},{"intersections":[{"location":[13.704755,51.085911],"entry":[true,true,false],"bearings":[69,161,343],"in":2,"out":0}],"driving_side":"right","geometry":"md`m`BebncYmPugA","mode":"driving","maneuver":{"bearing_after":0,"bearing_before":0,"location":[13.704755,51.085911],"modifier":"left","type":"turn","instruction":"turn left onto Jubiläumsstraße"},"weight":87.0,"duration":19.6,"name":"Jubiläumsstraße","distance":87.0,"voiceInstructions":[{"distanceAlongGeometry":25.0,"announcement":"arrive at destination","ssmlAnnouncement":"<speak><amazon:effect name=\"drc\"><prosody rate=\"1.08\">arrive at destination</prosody></amazon:effect></speak>"}],"bannerInstructions":[{"distanceAlongGeometry":87.0,"primary":{"text":"Arrive at destination","components":[{"text":"Arrive at destination","type":"text"}],"type":"arrive"},"secondary":null}]},{"intersections":[{"entry":[true],"bearings":[0],"in":0,"location":[13.705918,51.08619]}],"driving_side":"right","geometry":"{u`m`B{jpcY??","mode":"driving","maneuver":{"bearing_after":0,"bearing_before":0,"location":[13.705918,51.08619],"type":"arrive","instruction":"arrive at destination"},"weight":0.0,"duration":0.0,"name":"","distance":0.0,"voiceInstructions":[],"bannerInstructions":[]}],"summary":"GraphHopper Route 0","weight":33.3,"duration":33.3,"distance":209.1}],"weight_name":"routability","weight":36.4,"duration":33.3,"distance":209.1,"voiceLocale":"en"}],"waypoints":[{"name":"","location":[13.70423,51.086958]},{"name":"","location":[13.705918,51.08619]}],"code":"Ok","uuid":"e4e518ed5ffd4ed793ea5c3a5766ef96"}

via URL https://graphhopper.com/api/1/navigate/directions/v5/gh/car/13.70421,51.086954;13.706496,51.086818?geometries=polyline6&steps=true&roundabout_exits=true&voice_instructions=true&banner_instructions=true&access_token=pk.<API_KEY>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions