Created
July 13, 2016 18:23
-
-
Save matthijsotterloo/3def603f224d83f2b8f620f2174c535e to your computer and use it in GitHub Desktop.
Open location in Apple Maps using Swift.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func openMaps() { | |
let geocoder = CLGeocoder() | |
let str = "1600 Pennsylvania Ave. 20500" // A string of the address info you already have | |
geocoder.geocodeAddressString(str) { (placemarksOptional, error) -> Void in | |
if let placemarks = placemarksOptional { | |
print("placemark| \(placemarks.first)") | |
if let location = placemarks.first?.location { | |
let query = "?ll=\(location.coordinate.latitude),\(location.coordinate.longitude)" | |
let path = "http://maps.apple.com/" + query | |
if let url = NSURL(string: path) { | |
UIApplication.sharedApplication().openURL(url) | |
} else { | |
// Could not construct url. Handle error. | |
} | |
} else { | |
// Could not get a location from the geocode request. Handle error. | |
} | |
} else { | |
// Didn't get any placemarks. Handle error. | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment