Class

MKMapItem

The MKMapItem class encapsulates information about a specific point on a map. This information includes the map location and any other data that might be relevant, such as the name of a business at that location. Apps use this class to share map-related data with the Maps app.

Overview

You use this class in one of two ways. If your app is able to display point-to-point directions, the Maps app can send a directions request to your app in response to a request by the user to use your app for routing. In that case, the directions request contains map items with the start and end points to use when creating the directions. The second way to use map items is to create them in your app and then ask the Maps app to display them. For example, if your app allows the user to search for local businesses or points of interest, you can create a map item for each location and ask Maps to display pins at the corresponding locations.

Usually, you use this class to represent fixed locations on the map, but you can also use the forCurrentLocation() method to get a map item that represents the user’s current location. For privacy reasons, and because the user’s location can change, the map item returned by that method does not contain any coordinate data. When you need the actual location of the user, you must use the Core Location framework to retrieve it.

Symbols

Creating and Initializing Map Items

class func forCurrentLocation()

Creates and returns a singleton map item object representing the device’s current location.

init(placemark: MKPlacemark)

Initializes and returns a map item object using the specified placemark object.

Accessing the Map Item Attributes

var placemark: MKPlacemark

The placemark object containing the location information.

var isCurrentLocation: Bool

A Boolean value indicating whether the map item represents the user’s current location.

var name: String?

The descriptive name associated with the map item.

var phoneNumber: String?

The phone number associated with a business at the specified location.

var url: URL?

The URL associated with the specified location.

var timeZone: TimeZone?

The time zone of the specified location.

Launching the Maps App

class func openMaps(with: [MKMapItem], launchOptions: [String : Any]? = nil)

Open the Maps app and display the specified map items.

func openInMaps(launchOptions: [String : Any]? = nil)

Open the Maps app and display this map item.

Constants

Launch Options Dictionary Keys

Launch options to specify when opening map items in the Maps app.

Directions Mode Values

Strings representing the possible values of the MKLaunchOptionsDirectionsModeKey key.

Relationships

Inherits From

Conforms To