IOS - Open Apple Maps with Latitude and Longitude

I am developing an application to open an Apple Maps session and pass the latitude and longitude coordinates in order to get directions to this location from the current location of users.

I know that this can be done on google maps, which I already do, but when I try to open the URL on Apple Maps, it just opens a wrong place from the users' current location to the destination.

Here is the URL scheme I used:

http://maps.apple.com/?ll=(someLatitude),(someLongitute) 

the code:

 UIApplication.sharedApplication().openURL(NSURL(string:"http://maps.apple.com/?ll=\(locationLat),\(locationlong)")!) 

Any help would be greatly appreciated. Thanks!

+8
ios swift apple-maps
source share
2 answers

Try this code, AppleMap will open with directions marked from the current location of the device to the location indicated by the coordinates.

  let coordinate = CLLocationCoordinate2DMake(currentLat, currentLong) let mapItem = MKMapItem(placemark: MKPlacemark(coordinate: coordinate, addressDictionary:nil)) mapItem.name = "Destination/Target Address or Name" mapItem.openInMapsWithLaunchOptions([MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeDriving]) 
+17
source share

try using

 NSURL(string:"http://maps.apple.com/?saddr=\(currentLat),\(currentLong)&daddr=\(destinationLat),\(destinationLong)")! 

with currentLat, currentLong is the current location of users, and destinationLat destinationLong is the destination.

more parameters (for example: transport type) see here

+5
source share

All Articles