How to show locations on apple ios 6 maps with sharedApplication

in my application in ios 5 i have a button name on the map

For example, in the store detail view, there is a showinmap button, and this button goes to maps.google to show the current direction of the user and the direction of the store, and he also draws a line between these directions on how to get 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 application. instead, there is an app for the new Apple card.

now my problem is how can I change my code to do the same work with apple map application in ios6 versions?

+4
source share
2 answers

Just replace maps.google.com with 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 noted in his answer, it seems that Apple integrated it better than me, and you can specify all your URLs on maps.apple.com even in iOS5: Apple will automatically redirect your URLs to maps .google.com if you release them from your iOS5 device!

+6
source

While AliSoftware saves its hop with its own method. Technically, you only need to change maps.google.com to maps.apple.com . Apple redirects redirection to devices not related to iOS 6. I just wanted to clarify.

+3
source

Source: https://habr.com/ru/post/1436224/


All Articles