Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to show locations in ios 6 apple maps with sharedApplication

Tags:

ios

maps

ios6

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?

like image 387
ercan Avatar asked Dec 27 '22 17:12

ercan


2 Answers

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!

like image 145
AliSoftware Avatar answered Feb 09 '23 00:02

AliSoftware


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.

like image 21
Vagari Avatar answered Feb 08 '23 23:02

Vagari