Previous to iOS 6, opening a URL like this would open the (Google) Maps app:
NSURL *url = [NSURL URLWithString:@"http://maps.google.com/?q=New+York"];
[[UIApplication sharedApplication] openURL:url];
Now with the new Apple Maps implementation, this just opens Mobile Safari to Google Maps. How can I accomplish the same behavior with iOS 6? How do I programmatically open the Maps app and have it point to a specific location/address/search/whatever?
Best Answer
Here's the official Apple way:
If you want to get driving or walking instructions to the location, you can include a
mapItemForCurrentLocation
with theMKMapItem
in the array in+openMapsWithItems:launchOptions:
, and set the launch options appropriately.You can preserve your original iOS 5 and lower code in an
else
statement after thatif
. Note that if you reverse the order of items in theopenMapsWithItems:
array, you'll get directions from the coordinate to your current location. You could probably use it to get directions between any two locations by passing a constructedMKMapItem
instead of the current location map item. I haven't tried that.Finally, if you have an address (as a string) that you want directions to, use the geocoder to create an
MKPlacemark
, by way ofCLPlacemark
.