这里映射iOS distanceToDestination

时间:2016-08-25 17:53:28

标签: ios gps

我想知道是否有人可以帮助我在Heremap iOS sdk中获得总路线距离。根据该文件,以下应该做到这一点,但我只能找回与无限接近的价值观,而这只是邪恶的。有人可以提供一个有效的例子吗?我在模拟器中运行它,但这不应该真的重要。

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

NMAUint64 distance_i64 = [NMANavigationManager sharedNavigationManager].distanceToDestination;

2 个答案:

答案 0 :(得分:0)

您的第二次使用NMAUint64 distance = [NMANavigationManager sharedNavigationManager].distanceToDestination;没问题。然后你应该自己计算你的距离。以下是度量系统的示例

- (NSString *)distanceToMetricStringFromLongValue:(NMAUint64)value {
    NSString *distanceText = @"";
    if (value < 250) {
        NMAUint64 distance = (NMAUint64)round(value / 5.0) * 5;
        if (showZeroDistance || distance > 0) {
            distanceText = [NSString stringWithFormat:@"%lld m", distance];
        }
    } else if (value < 500) {
        NMAUint64 distance = (NMAUint64)round(value / 10.0) * 10;
        if (showZeroDistance || distance > 0) {
            distanceText = [NSString stringWithFormat:@"%lld m", distance];
        }
    } else if (value < 1000) {
        NMAUint64 distance = (NMAUint64)round(value / 50.0) * 50;
        distanceText = [NSString stringWithFormat:@"%lld m", distance];
    } else {
        double distance = value / 1000.0;
        if (distance >= 10.0) {
            distanceText = [NSString stringWithFormat:@"%0.0f km", round(distance)];
        } else {
            distanceText = [NSString stringWithFormat:@"%0.1f km", distance];
        }
    }
}

答案 1 :(得分:0)

使用以下方法在地图上创建路线时

- (nullable NSProgress *)calculateRouteWithStops:(nonnull NSArray *)stops
                                     routingMode:(nonnull NMARoutingMode *)mode
                                 completionBlock:(nullable NMACalculateResultBlock)completion

NMARoute对象

中查找路线长度
NMARoute* route = routeResult.routes[m];
NSLog(@"Route Length is :----- %lu",(unsigned long)route.length);

Official document link