SDK Here Navigate Flutter - 具有空值的机动对象

SDK Here Navigate Flutter - Maneuver object with null values

我为 Flutter 使用 SDK HERE Navigation 版本 4.5.4。

在导航过程中,我通过 routeProgressListener 对象的 routeProgressListener 侦听器获取下一个机动索引,然后在我的路线对象中获取机动对象。

但是对于我的路线的每一次演习,这些参数 return null :

但是参数 text return 我的值是正确的。

我的日志:

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's RouteProgress 中获取 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 而不是镖。 user guide 中对 Android 的解释很有帮助。 Flutter 似乎仍处于测试阶段,因此与原生版本相比,用户指南有点受限。