iOS Developer Library

Developer

MapKit Framework Reference MKDirectionsRequest Class Reference

Options
Deployment Target:

On This Page
Language:

MKDirectionsRequest

Inherits From


Conforms To


Import Statement


Swift

import MapKit

Objective-C

@import MapKit;

Availability


Available in iOS 6.0 and later

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.

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

    Declaration

    Swift

    class func isDirectionsRequestURL(_ url: NSURL!) -> Bool

    Objective-C

    + (BOOL)isDirectionsRequestURL:(NSURL *)url

    Parameters

    url

    The URL provided to your app.

    Return Value

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

    Import Statement

    Objective-C

    @import MapKit;

    Swift

    import MapKit

    Availability

    Available in iOS 6.0 and later

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

    Declaration

    Swift

    init!(contentsOfURL url: NSURL!)

    Objective-C

    - (instancetype)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.

    Import Statement

    Objective-C

    @import MapKit;

    Swift

    import MapKit

    Availability

    Available in iOS 6.0 and later

  • Returns the starting point for routing directions.

    Declaration

    Swift

    func source() -> MKMapItem!

    Objective-C

    - (MKMapItem *)source

    Return Value

    The starting point for routing directions.

    Import Statement

    Objective-C

    @import MapKit;

    Swift

    import MapKit

    Availability

    Available in iOS 6.0 and later

  • Sets the starting point for routing directions.

    Declaration

    Swift

    func setSource(_ source: MKMapItem!)

    Objective-C

    - (void)setSource:(MKMapItem *)source

    Parameters

    source

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

    Import Statement

    Objective-C

    @import MapKit;

    Swift

    import MapKit

    Availability

    Available in iOS 7.0 and later

  • Returns the end point for routing directions

    Declaration

    Swift

    func destination() -> MKMapItem!

    Objective-C

    - (MKMapItem *)destination

    Return Value

    The end point for routing directions.

    Import Statement

    Objective-C

    @import MapKit;

    Swift

    import MapKit

    Availability

    Available in iOS 6.0 and later

  • Sets the end point for routing directions

    Declaration

    Swift

    func setDestination(_ destination: MKMapItem!)

    Objective-C

    - (void)setDestination:(MKMapItem *)destination

    Parameters

    destination

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

    Import Statement

    Objective-C

    @import MapKit;

    Swift

    import MapKit

    Availability

    Available in iOS 7.0 and later

  • The type of conveyance to which the directions should apply.

    Declaration

    Swift

    var transportType: MKDirectionsTransportType

    Objective-C

    @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.

    Import Statement

    Objective-C

    @import MapKit;

    Swift

    import MapKit

    Availability

    Available in iOS 7.0 and later

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

    Declaration

    Swift

    var requestsAlternateRoutes: Bool

    Objective-C

    @property(nonatomic) BOOL requestsAlternateRoutes

    Discussion

    When this property is set to NOfalse, the server returns a single route between the start and end points. When this property is YEStrue, 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 NOfalse.

    Import Statement

    Objective-C

    @import MapKit;

    Swift

    import MapKit

    Availability

    Available in iOS 7.0 and later

  • The departure date for the trip.

    Declaration

    Swift

    @NSCopying var departureDate: NSDate!

    Objective-C

    @property(nonatomic, copy) 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.

    Import Statement

    Objective-C

    @import MapKit;

    Swift

    import MapKit

    Availability

    Available in iOS 7.0 and later

  • The arrival date for the trip.

    Declaration

    Swift

    @NSCopying var arrivalDate: NSDate!

    Objective-C

    @property(nonatomic, copy) 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.

    Import Statement

    Objective-C

    @import MapKit;

    Swift

    import MapKit

    Availability

    Available in iOS 7.0 and later

  • Constants that specify the type of conveyance to be used.

    Declaration

    Swift

    struct MKDirectionsTransportType : RawOptionSetType { init(_ rawValue: UInt) init(rawValue rawValue: UInt) static var Automobile: MKDirectionsTransportType { get } static var Walking: MKDirectionsTransportType { get } static var Any: MKDirectionsTransportType { get } }

    Objective-C

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

    Constants

    • Automobile

      MKDirectionsTransportTypeAutomobile

      Directions suitable for use while driving.

      Available in iOS 7.0 and later

    • Walking

      MKDirectionsTransportTypeWalking

      Directions suitable for a pedestrian.

      Available in iOS 7.0 and later

    • Any

      MKDirectionsTransportTypeAny

      Directions suitable for any transportation option.

      Available in iOS 7.0 and later

    Import Statement

    Objective-C

    @import MapKit;

    Swift

    import MapKit

    Availability

    Available in iOS 7.0 and later