我在iOS应用中实现了Here Maps导航SDK。
当我在开始导航之前计算路线时,我将路线保存在实例变量中:self.route
。
// Trigger the route calculation
[self.router
calculateRouteWithStops:stops
routingMode:routingMode
completionBlock:^(NMARouteResult* routeResult, NMARoutingError error) {
if (error) {
reject(@"route_calculation_error", [NSString stringWithFormat:@"Error %d when calculating route", (int)error], nil);
return;
}
if (!routeResult || routeResult.routes.count == 0) {
reject(@"route_calculation_no_result", @"Error when calculation route: no result", nil);
return;
}
// Let's add the 1st result onto the map
self.route = routeResult.routes[0];
self.mapRoute = [NMAMapRoute mapRouteWithRoute:self.route];
[self.mapView addMapObject:self.mapRoute];
[self zoomToRoute];
[self updateNavigationMode:kNavigationModeRoute];
resolve(@{
@"length" : @(self.route.length),
@"duration" : @(self.route.tta.duration),
});
}];
然后,当我调用停止导航的功能时,路线将从地图中删除,self.route
为零。我想在地图上保留路线并返回行程视图。
[self zoomToRoute];
[self.navigationManager stop]; // after this call, self.route == nil
[self updateNavigationMode:kNavigationModeRoute];
这是我提出的解决方案,但我宁愿不重新创建mapRoute
,感觉很讨厌......
[self zoomToRoute];
// for some reason navigationManger#stop releases self.route and removes
// the mapRoute from the map so we create it again
NMARoute* route = self.route;
[self.navigationManager stop];
self.route = route;
self.mapRoute = [NMAMapRoute mapRouteWithRoute:self.route];
[self.mapView addMapObject:self.mapRoute];
[self updateNavigationMode:kNavigationModeRoute];
答案 0 :(得分:0)
NMARoute的所有权独立于导航和所有其他环境。只要您的self.route保留了强引用,只要您的应用程序需要它,您就可以重复使用NMARoute对象。