Search code examples
iosswiftdirectionsapple-maps

Can't show the directions in iPhone's inbuilt Map application


This is my custom location set inside the iOS 10.0 iPhone 6 and iOS 11.2 iPhone 6 simulators.

enter image description here

And this is the code by which I am trying to open the iPhone's inbuilt Apple Map and show the directions from user's (above set) current location to the provided destination locations.

    let regionDistance: CLLocationDistance = 1000
    let coordinates = CLLocationCoordinate2D(latitude: 26.025860999999999, longitude: 56.089238999999999)
    let regionSpan = MKCoordinateRegionMakeWithDistance(coordinates, regionDistance, regionDistance)
    let options = [MKLaunchOptionsMapCenterKey: NSValue(mkCoordinate: regionSpan.center),
            MKLaunchOptionsMapSpanKey: NSValue(mkCoordinateSpan: regionSpan.span),
            MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving] as [String : Any]
    let placemark = MKPlacemark(coordinate: coordinates, addressDictionary: nil)
    let mapItem = MKMapItem(placemark: placemark)
    mapItem.name = "Federal Electricity & Water Authority"
    mapItem.openInMaps(launchOptions: options)

but this is not working for at all. It's showing me the error like below,

enter image description here

Note:

  1. I have given the location access permission to the default Map application.
  2. All 4 MKLaunchOptionsDirectionsModeKey is not showing the direction.
  3. Tested it on the Simulator and a real device and it is not working in either place.
  4. Setting destination coordinates like this doesn't help. let coordinates = CLLocationCoordinate2D(latitude: 26.025861, longitude: 56.089239)

Please help!


Solution

  • As Indrajeet commented, the directions in iPhone's Apple Map is limited to the countries which are listed in this URL.

    So in my case, UAE is not listed currently.

    Will update this answer in future once UAE will be listed.