SDK在这里导航Flutter-具有空值的机动对象



我使用Flutter的SDK HERE导航版本4.5.4。

在导航过程中,我通过VisualNavigator对象的routeProgressListener监听器获得下一个机动指标,然后在我的路线对象中获得机动对象。

但对于我路线上的每一次机动,这些参数都会返回null:

  • roadName
  • roadNameLanguageCode
  • roadNumber
  • nextRoadName
  • nextRoadNameLanguageCode
  • nextRoadNumber

但是参数text返回了一个正确的值。

我的日志:

flutter: NAV - nextHereManeuver :
action ManeuverAction.rightTurn 
text Turn right onto Rue Roquelaine. Go for 112 m. 
roadType null 
roadName null 
roadNameLanguageCode null 
roadNumber null 
nextRoadName null 
nextRoadNameLanguageCode null 
nextRoadNumber null
flutter: NAV - nextHereManeuver :
action ManeuverAction.rightTurn 
text Turn right onto Boulevard de Strasbourg. Go for 96 m. 
roadType null 
roadName null 
roadNameLanguageCode null 
roadNumber null 
nextRoadName null 
nextRoadNameLanguageCode null 
nextRoadNumber null
etc.

谢谢

基本上,在导航过程中,您应该从VisualNavigator'sRouteProgress中获取Maneuver对象,而不是从Route对象中获取。从Route获取的机动text包含本地化描述,但在导航过程中,从RouteProgress获取的值与null相同。

通常,我使用路线概览页面中的路线来绘制路线并显示机动列表,在导航过程中,我直接从导航器中获取机动,因为它们与您的当前位置实时同步。下面是更多的代码(在Dart中(,展示了如何从routeProgress中获取内容。它取自HERE SDK的GitHub回购,其中包含一些有用的Flutter示例:

// Contains the progress for the next maneuver ahead and the next-next maneuvers, if any.
List<ManeuverProgress> nextManeuverList = routeProgress.maneuverProgress;
ManeuverProgress nextManeuverProgress = nextManeuverList.first;
if (nextManeuverProgress == null) {
print('No next maneuver available.');
return;
}
int nextManeuverIndex = nextManeuverProgress.maneuverIndex;
HERE.Maneuver nextManeuver = _visualNavigator.getManeuver(nextManeuverIndex);
if (nextManeuver == null) {
// Should never happen as we retrieved the next maneuver progress above.
return;
}
HERE.ManeuverAction action = nextManeuver.action;
String nextRoadName = nextManeuver.nextRoadName;
String road = nextRoadName ?? nextManeuver.nextRoadNumber;
if (action == HERE.ManeuverAction.arrive) {
// We are approaching the destination, so there's no next road.
String currentRoadName = nextManeuver.roadName;
road = currentRoadName ?? nextManeuver.roadNumber;
}
// Happens only in rare cases, when also the fallback is null.
road ??= 'unnamed road';

所以,基本上,在导航过程中,你可以得到这样的maneuver(忽略route实例,它也包含机动(:

Maneuver nextManeuver = visualNavigator.getManeuver(nextManeuverIndex);

我还建议看一下Android版本的用户指南,它包含相同的SDK逻辑,只是API接口是Java/Kotlin而不是Dart。Android用户指南中的解释非常有用。Flutter似乎仍处于测试阶段,因此与本土口味相比,用户指南有点有限。

最新更新