Here is a strange problem: My app should be able to call the built in Maps in iOS (both 5.1 and 6). Turns out that it works just fine under iOS6 but not under iOS5.1. The maps in iOS6 is called and the directions from saddr to daddr is traced but when I am in iOS5 the maps app is called but just one pin is put at the daddr. For some unknown reason the initial coordinates (saddr) are not showing and no direction is traced.
Here is my code:
addr = [NSString stringWithFormat: @"maps://saddr=%f,%f&daddr=%f,%f", newLocation.coordinate.latitude, newLocation.coordinate.longitude, oldLatitude, oldLongitude];
NSURL *url = [NSURL URLWithString:addr];
[[UIApplication sharedApplication] openURL:url];
I have tried change the URL to "http://maps.google.com/something" but it calls Safari instead of built in Maps app. I have noticed that the variables are being passed properly to the URL.
Any ideas?
Thanks in advance!
You can use
MKPlacemark
andMKMapItem
to launch the Maps app with both a coordinate and a title on the map pin:Note that you'll need to link against
AddressBook.framework
and also add#import <AddressBook/AddressBook.h>
somewhere in your code to make use of thekABPersonAddressStreetKey
constant.I had a similar problem and I had to create some conditional OS code to deal with the fact that the Google Maps application has been removed. From the new MKMapItem Reference
To get walking directions:
MKLaunchOptionsDirectionsModeWalking
instead ofMKLaunchOptionsDirectionsModeDriving
&dirflg=w
to the url.I think it's better to use the openInMapsWithLaunchOptions in iOS6 because it gives you complete control over how the maps application will respond.