4

在我的 ios 5 应用程序中,我在地图中显示了一个按钮名称

例如,在商店详细信息视图中,有一个 showinmap 按钮,此按钮转到 maps.google 以显示用户的当前方向和商店方向,并且它还在这些方向之间绘制一条关于如何去那里的线

这是我的方法:

NSString* url = [NSString stringWithFormat: @"http://maps.google.com/maps?saddr=Current+Location&daddr=%@,%@",lonlocation,latlocation];  

[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];                  

但在 ios 6 中,您知道没有谷歌地图应用程序。取而代之的是苹果的新地图应用程序。

现在我的问题是如何更改我的代码以在 ios6 版本中使用苹果地图应用程序完成相同的工作?

4

2 回答 2

7

只需在您的网址中替换maps.google.commaps.apple.com,它就像一个魅力:)

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]];                  

[编辑] 正如@Vagari 在他的回答中指出的那样,Apple 似乎比我更好地集成了它,maps.apple.com即使在 iOS5 中你也可以将所有 URL 指向:如果你发出它们,Apple 会自动将你的 URL 重定向到 maps.google.com从 iOS5 上的设备!

于 2012-09-25T20:09:23.663 回答
3

而 AliSoftware 用他的方法节省了一跳。从技术上讲,您只需将 更改maps.google.commaps.apple.com。Apple 将重定向推送到不在 iOS 6 上的设备。只是想澄清一下。

于 2012-10-02T17:02:18.453 回答