HERE SDK for iOS (Premium Edition)

SDK for iOS Developer's Guide

Distance calculations between points

Calculating the absolute distance between two points

Following example explains how to calculate absolute distance between two points using the Haversine formula, ignoring any kind of roads or similar.

NMAGeoCoordinates *start = [[NMAGeoCoordinates alloc] initWithLatitude:49.839740
                               longitude:24.029272];
NMAGeoCoordinates *end = [[NMAGeoCoordinates alloc] initWithLatitude:49.843667
                               longitude:24.026510];
// distance in meters
double distance = [start distanceTo:end];

Calculating the distance along a route

Following example explains how to calculate distance along a route. Use particular route options to get needed route.

// setup waypoints
NMAGeoCoordinates *start = [[NMAGeoCoordinates alloc] initWithLatitude:49.839882
                               longitude:24.029239];
NMAGeoCoordinates *end = [[NMAGeoCoordinates alloc] initWithLatitude:49.849897
                              longitude:24.022307];
NMAWaypoint *startWaypoint = [[NMAWaypoint alloc] initWithGeoCoordinates:start];
NMAWaypoint *endWaypoint = [[NMAWaypoint alloc] initWithGeoCoordinates:end];

// setup mode
NMARoutingMode *mode = [[NMARoutingMode alloc] initWithRoutingType:NMARoutingTypeFastest
                           transportMode:NMATransportModeCar
                          routingOptions:0];
// calculate a route
_router = [[NMACoreRouter alloc] init];
[_router calculateRouteWithStops:@[startWaypoint, endWaypoint]
           routingMode:mode
         completionBlock:^(NMARouteResult *result, NMARoutingError error) {
  if (error == NMARoutingErrorNone && result.routes.count > 0) {
    // distance in meters
    NSUInteger distance = [result.routes firstObject].length;
  }
}];