Type Method

openMaps(with:launchOptions:)

Open the Maps app and display the specified map items.

Declaration

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

Parameters

mapItems

An array containing one or more MKMapItem objects representing the items you want to display on the map.

launchOptions

Additional information that the Maps app can use to configure the map display. For example, you can use the launch options to specify the visible map region, a 3D perspective, and the map type. For a list of keys you can put into this dictionary, see Launch Options Dictionary Keys.

You may specify nil for this parameter.

Return Value

true if the map items were successfully opened by the Maps app, or false if there was an error.

Discussion

You use this method to pass one or more map items to the Maps app. For example, you might use this method to ask the Maps app to display location-based search results generated by your app. Maps displays pins at each location you specify and uses the contents of each map item object to display additional information.

If you specify the MKLaunchOptionsDirectionsModeKey option in the launchOptions dictionary, the mapItems array must have no more than two items in it. If the array contains one item, the Maps app generates directions from the user’s current location to the location specified by the map item. If the array contains two items, the Maps app generates directions from the location of the first item to the location of the second item in the array.

If you do not include the MKLaunchOptionsMapCenterKey and MKLaunchOptionsMapSpanKey keys in your launchOptions dictionary, Maps constructs a region that encompasses the provided items. It uses this region to set the visible portion of the map.

See Also

Launching the Maps App

func openInMaps(launchOptions: [String : Any]?) -> Bool

Open the Maps app and display this map item.