【发布时间】:2018-01-17 16:54:32
【问题描述】:
我正在 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,感觉很hacky...
[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];
【问题讨论】:
标签: objective-c here-api