我想在我的 Iphone 应用程序中打开设备映射以在源和目标之间绘制路径,如下图所示。
如何在我的 Iphone 应用程序中打开设备映射,如上图?
使用以下代码打开地图应用程序,
NSString *url;
if([[[UIDevice currentDevice] systemVersion] compare:@"6.0" options:NSNumericSearch] == NSOrderedAscending)
{
url = [NSString stringWithFormat:@"http://maps.google.com/maps?daddr=%@,%@&saddr=%@,%@",[dict objectForKey:@"latitude"],[dict objectForKey:@"longitude"],currentLat,currentLong];
}
else
{
url = [NSString stringWithFormat:@"http://maps.apple.com/maps?daddr=%@,%@&saddr=%@,%@",[dict objectForKey:@"latitude"],[dict objectForKey:@"longitude"],currentLat,currentLong];
}
if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:url]])
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
}
iOS 6.0 及以上版本有苹果地图应用程序,iOS 较低版本你必须打开谷歌地图应用程序。在网址中,
daddr=%@,%@&saddr=%@,%@
daddr
是目的地址,saddr
是源地址。