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?
//VKJ
Before launching url, remove any special character from the url and replace spaces by +. This will save you some headaches:
Found the answer to my own question. Apple documents its maps URL format here. It looks like you can essentially replace
maps.google.com
withmaps.apple.com
.Update: It turns out that the same is true in MobileSafari on iOS 6; tapping a link to
http://maps.apple.com/?q=...
opens the Maps app with that search, the same wayhttp://maps.google.com/?q=...
did on previous versions. This works and is documented in the page linked above.UPDATE: This answers my question relating to the URL format. But nevan king's answer here (see below) is an excellent summary of the actual Maps API.
Here is a class using nevan king's solution completed in Swift:
Not using maps, just programmatically using a UiButton action, this worked great for me.
You could spread some of this code out a bit. For example, I put the variable as a class level variable, had another function fill it, and then when pressed the button simply took what was in the variable and scrubbed it to be used in a URL.
I found it annoying that using the http://maps.apple.com?q=... link setup opens the safari browser first at older devices.
So for an iOS 5 device opening up your app with a reference to maps.apple.com the steps look like:
I think that the (very obvious and confusing) steps 2 and 3 are annoying to users. Therefore i check the os version and either run maps.google.com or maps.apple.com on the device (for resp. ios 5 or ios 6 OS versions).