Vikas Ojha Vikas Ojha - 4 months ago 7
iOS Question

calculate time taken to cover a journey in Apple Maps

I am working on MKMapView to get the direction between 2 locations.Is there any way i can get the time it may take in completing this journey?Is there any inbuilt property of

MKRoute or MKDirection
Class that can provide me time to cover this journey ?

Any help would be appreciated.

Thanks
Vikas

Answer

Yes.

The MKDirections method named calculateETAWithCompletionHandler: can just be a bit easy to overlook, though.

An implementation could look as follows:

MKDirections *yourDirections = ...;

[yourDirections calculateETAWithCompletionHandler:^(MKETAResponse *response, NSError *error)
{
     NSTimeInterval estimatedTravelTimeInSeconds = response.expectedTravelTime;
     ...
}];

Source:

https://developer.apple.com/library/mac/documentation/MapKit/Reference/MKDirections_class/Reference/Reference.html

Comments