Google Maps API Isn't the Only Directions Game in Town

If you are building an app that includes mapping directions, you may be worried about hitting the Google Maps API limit of 2,500 direction requests within a 24 hour period before having to pay up for a higher quota.

With iOS 7, Apple has now added a directions API that is free, and only has per-device throttling. That means that if your app goes full on Flappy Bird, you won’t need to worry about having to pay up1.

Like the Maps app itself, MKDirections currently only supports walking and driving directions (although keep an eye out for the MKDirectionsTransportType enum in future API diffs).

It’s a fairly simple API to use. First, you create a MKDirectionsRequest object:

1
2
3
4
5
MKDirectionsRequest *request = [MKDirectionsRequest new];
request.transportType = MKDirectionsTransportTypeWalking;
request.source = [MKMapItem mapItemForCurrentLocation]; // start from the users current location
request.destination = [MKMapItem initWithPlacemark:selectedPlacemark];
request.departureDate = [NSDate date]; // Departing now

Then create a MKDirections instance (storing in a property if we need to cancel it later):

1
self.directions = [[MKDirections alloc] initWithRequest:request];

You can either request all the routing information between those two points2, or you can request just the estimated time of arrival3.

1
2
3
[self.directions calculateETAWithCompletionHandler:^(MKETAResponse *response, NSError *error) {
    self.walkingTime.text = [formatter stringForTimeInterval:response.expectedTravelTime];
}];

There is nothing in the documentation or App Store Guidelines to suggest that you can’t use these directions with a different mapping technology (like Google Maps or MapBox).


  1. Well, other than the 30% cut Apple takes

  2. Using the calculateDirectionsWithCompletionHandler: method

  3. Uses the TTTTimeIntervalFormatter for creating a human readable string