MKDirectionsRequest Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/MapKit.framework
Availability
Available in iOS 6.0 and later.
Companion guide
Declared in
MKDirectionsRequest.h
MKDirectionsTypes.h

Overview

The MKDirectionsRequest class is used by apps that work with turn-based directions. When the Maps app sends a directions-related URL to your app, you use this class to decode the URL contents and determine the start and end points of a route. You then use that data to compute the actual route and display the results to the user. For apps that want to supplement their own routing directions, you can also use instances of this class to specify route information that you want from Apple.

For apps that provide directions, upon receiving a URL in your app delegate’s application:openURL:sourceApplication:annotation: method, use the isDirectionsRequestURL: method of this class to determine if the URL is related to routing directions. If it is, create an instance of this class using the provided URL and extract the map items associated with the start and end points. You can then use those points to begin your route planning.

You can use this class to request directions for modes of transportation that your app does not natively handle. For example, an app that provides subway directions might request walking directions to and from relevant subway stations. To request directions, create a new instance of this class and configure it with the new start and end points you need. Then create a MKDirections object and use the methods of that class to initiate the request and process the results.

Tasks

Creating a Directions Request Object

Accessing the Start and End Points

Specifying Transportation Options

Properties

arrivalDate

The arrival date for the trip.

@property (nonatomic, retain) NSDate *arrivalDate;
Discussion

Specifying an arrival date provides the server with extra information that it can use to optimize the returned routes. For example, for a trip that takes place during commute hours, the server might consider alternatives to routes that are typically congested at that time.

The use of this property is optional.

Availability
  • Available in iOS 7.0 and later.
Declared In
MKDirectionsRequest.h

departureDate

The departure date for the trip.

@property (nonatomic, retain) NSDate *departureDate;
Discussion

Specifying a departure date provides the server with extra information that it can use to optimize the returned routes. For example, for a trip that takes place during commute hours, the server might consider alternatives to routes that are typically congested at that time.

The use of this property is optional.

Availability
  • Available in iOS 7.0 and later.
Declared In
MKDirectionsRequest.h

requestsAlternateRoutes

A Boolean indicating whether your app wants multiple routes when they are available.

@property (nonatomic) BOOL requestsAlternateRoutes;
Discussion

When this property is set to NO, the server returns a single route between the start and end points. When this property is YES, the server may return additional routes for the user to follow. The server returns additional routes only if they are available and represent a reasonable path that the user might take.

The default value of this property is NO.

Availability
  • Available in iOS 7.0 and later.
Declared In
MKDirectionsRequest.h

transportType

The type of conveyance to which the directions should apply.

@property (nonatomic) MKDirectionsTransportType transportType;
Discussion

You can use this property to specify whether you want directions suited to a particular type of transportation. For example, you can use this to specify that you want walking directions or driving directions.

The default value of this property is MKDirectionsTransportTypeAny.

Availability
  • Available in iOS 7.0 and later.
Declared In
MKDirectionsRequest.h

Class Methods

isDirectionsRequestURL:

Returns a Boolean indicating whether the specified URL contains a directions request.

+ (BOOL)isDirectionsRequestURL:(NSURL *)url
Parameters
url

The URL provided to your app.

Return Value

YES if the URL contains a directions request that your app should display to the user or NO if it does not.

Availability
  • Available in iOS 6.0 and later.
Declared In
MKDirectionsRequest.h

Instance Methods

destination

Returns the end point for routing directions

- (MKMapItem *)destination
Return Value

The end point for routing directions.

Availability
  • Available in iOS 6.0 and later.
Declared In
MKDirectionsRequest.h

initWithContentsOfURL:

Initializes and returns a directions request object using the specified URL.

- (id)initWithContentsOfURL:(NSURL *)url
Parameters
url

The URL provided to your app.

Return Value

An initialized directions request object.

Discussion

You should use the isDirectionsRequestURL: method to verify that the specified URL is of the correct format before calling this method to initialize the object.

Availability
  • Available in iOS 6.0 and later.
Declared In
MKDirectionsRequest.h

setDestination:

Sets the end point for routing directions

- (void)setDestination:(MKMapItem *)destination
Parameters
destination

The map item that represents the end point for routing directions.

Availability
  • Available in iOS 7.0 and later.
Declared In
MKDirectionsRequest.h

setSource:

Sets the starting point for routing directions.

- (void)setSource:(MKMapItem *)source
Parameters
source

The map item that represents the starting point for routing directions.

Availability
  • Available in iOS 7.0 and later.
Declared In
MKDirectionsRequest.h

source

Returns the starting point for routing directions.

- (MKMapItem *)source
Return Value

The starting point for routing directions.

Availability
  • Available in iOS 6.0 and later.
Declared In
MKDirectionsRequest.h

Constants

MKDirectionsTransportType

Constants that specify the type of conveyance to be used.

typedef enum {
   MKDirectionsTransportTypeAutomobile     = 1 << 0,
   MKDirectionsTransportTypeWalking        = 1 << 1,
   MKDirectionsTransportTypeAny            = NSUIntegerMax
} MKDirectionsTransportType;
Constants
MKDirectionsTransportTypeAutomobile

Directions suitable for use while driving.

Available in iOS 7.0 and later.

Declared in MKDirectionsTypes.h.

MKDirectionsTransportTypeWalking

Directions suitable for a pedestrian.

Available in iOS 7.0 and later.

Declared in MKDirectionsTypes.h.

MKDirectionsTransportTypeAny

Directions suitable for any transportation option.

Available in iOS 7.0 and later.

Declared in MKDirectionsTypes.h.