HERE SDK导航版(4.13.2.0)如何获取当前路名

问题描述 投票:0回答:1

我有

com.here.sdk.routing.Route
VisualNavigator
RouteProgressListener
(和其他听众)并开始导航。 我在
RouteProgress
收到必要的
onRouteProgressUpdated

Route?.sections?.forEach {
    it.maneuvers.forEach {
        it?.roadTexts?.names?.defaultValue   // here is null very often
    }
}
routeProgress.maneuverProgress.forEach {
            val maneuver = it?.maneuverIndex?.let { it1 -> VisualNavigator.getManeuver(it1) }
            maneur?.roadTexts?.names?.defaultValue   //here is null all the time
        }

我怎样才能得到当前的道路(街道)名称(正确的方式)?

android navigation maps here-api
1个回答
0
投票

这样可以得到路名-

private fun getRoadName(maneuver: Maneuver): String? {
        val currentRoadTexts = maneuver.roadTexts
        val nextRoadTexts = maneuver.nextRoadTexts
        val currentRoadName = currentRoadTexts.names.defaultValue
        val currentRoadNumber = currentRoadTexts.numbers.defaultValue
        val nextRoadName = nextRoadTexts.names.defaultValue
        val nextRoadNumber = nextRoadTexts.numbers.defaultValue
        var roadName = nextRoadName ?: nextRoadNumber

        // On highways, we want to show the highway number instead of a possible road name,
        // while for inner city and urban areas road names are preferred over road numbers.
        if (maneuver.nextRoadType == RoadType.HIGHWAY) {
            roadName = nextRoadNumber ?: nextRoadName
        }
        if (maneuver.action == ManeuverAction.ARRIVE) {
            // We are approaching the destination, so there's no next road.
            roadName = currentRoadName ?: currentRoadNumber
        }
        if (roadName == null) {
            // Happens only in rare cases, when also the fallback is null.
            roadName = "unnamed road"
        }
        return roadName
    }

希望这能回答您的问题。

© www.soinside.com 2019 - 2024. All rights reserved.