in my app in ios 5 i have a button name show in map
forexample in a store detail view there is a showinmap button and this button goes to maps.google to show the user's current direction and the store direction and also it draws a line between these direction about how to go there
this was my method:
NSString* url = [NSString stringWithFormat: @"http://maps.google.com/maps?saddr=Current+Location&daddr=%@,%@",lonlocation,latlocation];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];
but in ios 6 as you know there is no google maps app. instead of that there is apple's new map app.
now my problem is how can i change my code to do the same job with apple map app in ios6 versions?
Simply replace maps.google.com
by maps.apple.com
in your URL and it works like a charm :)
CGFloat sysVers = [UIDevice currentDevice].systemVersion.floatValue;
NSString* hostName = (sysVers < 6.0) ? @"maps.google.com" : @"maps.apple.com";
NSString* url = [NSString stringWithFormat: @"http://%@/maps?saddr=Current+Location&daddr=%@,%@",hostName,lonlocation,latlocation];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];
[EDIT] As @Vagari pointed out in his answer, it seems that Apple integrated it better than I though and you can point all your URLs to maps.apple.com
even in iOS5: Apple will automatically redirect your URLs to maps.google.com if you emit them from a device on iOS5!
While AliSoftware saves a hop with his method. Technically you only have to change the maps.google.com
to maps.apple.com
. Apple pushes a redirect to devices not on iOS 6. Just wanted to clarify.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With