HERE地图距离目的地始终返回高价值

时间:2016-01-09 10:09:41

标签: ios objective-c here-api here-ios

我在这里的地图中计算了一条路线,并使用该路线开始了Turn-by-Turn导航。一切都在离线工作正常,当我尝试使用

计算到达目的地的距离
double distance = [NMANavigationManager sharedNavigationManager].distanceToDestination; 

上述方法返回的值非常高,例如184467440737095520000.即使对于不同的路由,返回的值也始终为184467440737095520000。当我推荐导航管理器委托时,我发现此方法将以米为单位返回值。但即使这个返回的值太高了我目的地的距离..请指导我如何正确计算到目的地的距离..提前感谢

-(void)CalculateRoute:(NMARoutingMode *)routingMode
{

routeManager = [NMARouteManager sharedRouteManager];
routeManager.delegate = self;
NSMutableArray* stopList = [NSMutableArray array];
[stopList addObject:_StartCoordinate];
[stopList addObject:_DestinationCoordinate];

NSLog(@"routing from [%.5f,%.5f] to [%.5f,%.5f]", ((NMAGeoCoordinates*)stopList[0]).latitude, ((NMAGeoCoordinates*)stopList[0]).longitude,
      ((NMAGeoCoordinates*)stopList[1]).latitude, ((NMAGeoCoordinates*)stopList[1]).longitude);
NSLog(@"routingMode===>%@",routingMode.description);


[routeManager calculateRouteWithStops:stopList routingMode:routingMode];
 }


-(IBAction)StartNav:(UIButton*)sender
{
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(positionDidUpdate)
                                             name:NMAPositioningManagerDidUpdatePositionNotification

                                           object:[NMAPositioningManager sharedPositioningManager]];
[NMANavigationManager sharedNavigationManager].map = self.mapView;
[NMANavigationManager sharedNavigationManager].delegate = self;
[NMANavigationManager sharedNavigationManager].mapTrackingAutoZoomEnabled = YES;
[NMANavigationManager sharedNavigationManager].mapTrackingEnabled = YES;
[NMANavigationManager sharedNavigationManager].mapTrackingOrientation = NMAMapTrackingOrientationDynamic;
[NMANavigationManager sharedNavigationManager].speedWarningEnabled = YES;
[NMANavigationManager sharedNavigationManager].mapTrackingTilt = NMAMapTrackingTilt2D;
[[NMANavigationManager sharedNavigationManager]startTurnByTurnNavigationWithRoute:_route];
}

2 个答案:

答案 0 :(得分:1)

计算距离时出现错误。值 184467440737095520000 等于 NMANavigationManagerInvalidValue 常量。

尝试计算您的位置更新时的距离,所以请按照您提到的 positionDidUpdate 方法进行计算:

double distance = [NMANavigationManager sharedNavigationManager].distanceToDestination;

如果你想在调用 startTurnByTurnNavigationWithRoute 方法后第一次这样做,你应该从路线获得这样的信息:

double distance = _route.length;

顺便说一下,如果你尝试对timeToArrival做同样的事情,你也会获得很高的价值。

答案 1 :(得分:0)

distanceToDestination 一个double值。它是unsigned long long值或NMAUint64值。

请执行以下操作:

unsigned long long distance = [NMANavigationManager sharedNavigationManager].distanceToDestination; 

NMAUint64 distance = [NMANavigationManager sharedNavigationManager].distanceToDestination;