SDK Here Navigate Flutter - Maneuver object with null values

纵饮孤独 提交于 2020-12-13 05:42:06

问题


I use SDK HERE Navigation version 4.5.4 for Flutter.

During navigation, I get the next maneuver index through routeProgressListener listener of VisualNavigator object, then I get the maneuver object in my route object.

But for each maneuvers of my route those parameters return null :

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

But the parameter text return me a correct value.

My logs:

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.

Thank you


回答1:


Basically, during navigation you should take the Maneuver object from the VisualNavigator's RouteProgress, instead of taking it from the Route object instead. The maneuver's text taken from Route contains a localized description, but taking the same value from the RouteProgress is null during navigation.

Usually, I use the route for the route overview page to draw the route and show the maneuver list - and during navigation I take the maneuvers directly from navigator - as they are synced realtime with your current location. Here's some more code (in Dart) that shows how to get the content from routeProgress. It's taken from the HERE SDK's GitHub repo that contains some useful Flutter examples:

// 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';

So, basically, during navigation, you can get the maneuver like this (ignoring the route instance, which also contains maneuvers):

Maneuver nextManeuver = visualNavigator.getManeuver(nextManeuverIndex);

I would recommend to also take a look at the user guide for the Android flavor, it contains the same SDK logic, just the API interfaces are in Java/Kotlin instead of Dart. The explanations in user guide for Android are quite helpful. It seems Flutter is still in beta, so the user guide is a bit limited in comparison to the native flavors.



来源:https://stackoverflow.com/questions/65087273/sdk-here-navigate-flutter-maneuver-object-with-null-values

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!