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?
If you want to open Google Maps instead (or offer as a secondary option), you can use the
comgooglemaps://
andcomgooglemaps-x-callback://
URL schemes documented here.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
.My research on this issue lead me to the following conclusions:
Updated to Swift 4 based on @PJeremyMalouf's answer:
I see you found the maps.apple.com url "scheme". It's a good choice because it will automatically redirect older devices to maps.google.com. But for iOS 6 there is a new class you might want to take advantage of: MKMapItem.
Two methods that are of interest to you:
The best way to do it is to call new iOS 6 method on
MKMapItem
openInMapsWithLaunchOptions:launchOptions
Example:
This will start the navigation for driving from the current location.