前言

  • App内根据手机上装载的地图App将其显示在弹出的选择框,选择对应地图跳转进入地图导航。需要用到- (BOOL)canOpenURL:(NSURL *)url NS_AVAILABLE_IOS(3_0);方法判断手机是否已安装相应地图App。
  • 要进行跳转需要先在xcode的plist文件内将目标App的url Scheme加入白名单(LSApplicationQueriesSchemes)。

常见第三方地图App的url Scheme

  • 百度地图:baidumap
  • 高德地图:iosamap
  • 谷歌地图:comgooglemaps
  • 腾讯地图:qqmap

plist文件新增LSApplicationQueriesSchemes关键字,类型为NSArray,并在其下添加子目录,类型为NSString,内容为各地图对应的url Scheme。

白名单LSApplicationQueriesSchemes:

          

代码示例

//导航只需要目的地经纬度,endLocation为纬度、经度的数组
-(void)doNavigationWithEndLocation:(NSArray *)endLocation
{ //NSArray * endLocation = [NSArray arrayWithObjects:@"26.08",@"119.28", nil]; NSMutableArray *maps = [NSMutableArray array]; //苹果原生地图-苹果原生地图方法和其他不一样
NSMutableDictionary *iosMapDic = [NSMutableDictionary dictionary];
iosMapDic[@"title"] = @"苹果地图";
[maps addObject:iosMapDic]; //百度地图
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"baidumap://"]]) {
NSMutableDictionary *baiduMapDic = [NSMutableDictionary dictionary];
baiduMapDic[@"title"] = @"百度地图";
NSString *urlString = [[NSString stringWithFormat:@"baidumap://map/direction?origin={{我的位置}}&destination=latlng:%@,%@|name=北京&mode=driving&coord_type=gcj02",endLocation[0],endLocation[1]] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
baiduMapDic[@"url"] = urlString;
[maps addObject:baiduMapDic];
} //高德地图
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"iosamap://"]]) {
NSMutableDictionary *gaodeMapDic = [NSMutableDictionary dictionary];
gaodeMapDic[@"title"] = @"高德地图";
NSString *urlString = [[NSString stringWithFormat:@"iosamap://navi?sourceApplication=%@&backScheme=%@&lat=%@&lon=%@&dev=0&style=2",@"导航功能",@"nav123456",endLocation[0],endLocation[1]] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
gaodeMapDic[@"url"] = urlString;
[maps addObject:gaodeMapDic];
} //谷歌地图
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"comgooglemaps://"]]) {
NSMutableDictionary *googleMapDic = [NSMutableDictionary dictionary];
googleMapDic[@"title"] = @"谷歌地图";
NSString *urlString = [[NSString stringWithFormat:@"comgooglemaps://?x-source=%@&x-success=%@&saddr=&daddr=%@,%@&directionsmode=driving",@"导航测试",@"nav123456",endLocation[0], endLocation[1]] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
googleMapDic[@"url"] = urlString;
[maps addObject:googleMapDic];
} //腾讯地图
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"qqmap://"]]) {
NSMutableDictionary *qqMapDic = [NSMutableDictionary dictionary];
qqMapDic[@"title"] = @"腾讯地图";
NSString *urlString = [[NSString stringWithFormat:@"qqmap://map/routeplan?from=我的位置&type=drive&tocoord=%@,%@&to=终点&coord_type=1&policy=0",endLocation[0], endLocation[1]] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
qqMapDic[@"url"] = urlString;
[maps addObject:qqMapDic];
} //选择
UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"选择地图" message:nil preferredStyle:UIAlertControllerStyleActionSheet]; NSInteger index = maps.count; for (int i = 0; i < index; i++) { NSString * title = maps[i][@"title"]; //苹果原生地图方法
if (i == 0) { UIAlertAction * action = [UIAlertAction actionWithTitle:title style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
[self navAppleMap];
}];
[alert addAction:action]; continue;
} UIAlertAction * action = [UIAlertAction actionWithTitle:title style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { NSString *urlString = maps[i][@"url"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
}]; [alert addAction:action]; } [self presentViewController:alert animated:YES completion:nil]; } //苹果地图
- (void)navAppleMap
{
// CLLocationCoordinate2D gps = [JZLocationConverter bd09ToWgs84:self.destinationCoordinate2D]; //终点坐标
CLLocationCoordinate2D loc = CLLocationCoordinate2DMake(26.08, 119.28); //用户位置
MKMapItem *currentLoc = [MKMapItem mapItemForCurrentLocation];
//终点位置
MKMapItem *toLocation = [[MKMapItem alloc]initWithPlacemark:[[MKPlacemark alloc]initWithCoordinate:loc addressDictionary:nil] ]; NSArray *items = @[currentLoc,toLocation];
//第一个
NSDictionary *dic = @{
MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeDriving,
MKLaunchOptionsMapTypeKey : @(MKMapTypeStandard),
MKLaunchOptionsShowsTrafficKey : @(YES)
};
//第二个,都可以用
// NSDictionary * dic = @{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving,
// MKLaunchOptionsShowsTrafficKey: [NSNumber numberWithBool:YES]}; [MKMapItem openMapsWithItems:items launchOptions:dic]; }

参考链接:IOS实现应用内打开第三方地图app进行导航

iOS调用第三方地图App进行导航方法的更多相关文章

  1. Android和IOS启动第三方地图APP

    最近客户新提了需求,地址字段要能通过第三方的地图进行定位,于是对Android和IOS端进行了调整. 以下是调用地图部分的代码. android可按照包名来判断app是否存在: 方法: /* * ch ...

  2. iOS 调用第三方地图进行导航

    //支持的地图 { _model = model; //支持的地图 NSMutableArray *maps = [NSMutableArray array]; //苹果原生地图-苹果原生地图方法和其 ...

  3. Android开发 PopupWindow弹窗调用第三方地图(百度,高德)实现导航功能

    博客描述:后台返回地点的经纬度在地图上进行描点,点击导航弹出PopupWindow进行选择地图操作,如果手机中没有安装地图,提示没有,否则传值调起地图进行导航操作 看一下实现的效果,没图说再多都白搭 ...

  4. ios调用第三方程序打开文件,以及第三方调用自己的APP打开文件

    1.自己的APP调用第三方打开文件 主要是使用  UIDocumentInteractionController  类   并实现 UIDocumentInteractionControllerDel ...

  5. iOS调用第三方API/Framework

    前言 老板不止一次地说过:这个世纪靠个人的能力去完成一件事情肯定是不够的.无论什么方面我们都可以找到许许多多的事例表明合作共赢的重要性,例如Linux的发展.建筑事务所的发展.乃至科学技术的发展等等. ...

  6. ios调用百度地图定位遇到的奇葩问题

    app项目过程中需要用到百度地图,然后网上可以查资料看官网文档,最后弄了好几天还是不行,找了各位前辈帮忙虽然解决了,但是把代码拷贝到我的项目时又无法定位了,最后查看了下原因是info配置出了问题,不是 ...

  7. ios调用Google地图

    现在的ios版本一般只支持https协议,而引用谷歌地图API时只提供src="http://maps.google.cn/maps/api/js..",https协议无法使用,解 ...

  8. iOS调用第三方导航和线路规划

    线路规划: https://blog.csdn.net/qq_19979539/article/details/51938995 百度地图:baidumap: 高德地图:iosamap: 腾讯地图:q ...

  9. iOS APP中第三方APP调用自己的APP,打开文件

    根据需求需要在项目中要打开word.pdf.excel等文件,在info.plist文件中添加 <key>CFBundleDocumentTypes</key> <arr ...

随机推荐

  1. 乘积尾零|2018年蓝桥杯B组题解析第三题-fishers

    标题:乘积尾零 如下的10行数据,每行有10个整数,请你求出它们的乘积的末尾有多少个零? 5650 4542 3554 473 946 4114 3871 9073 90 4329 2758 7949 ...

  2. CodeCombat最后一题GridMancer

    http://codecombat.com/play/level/gridmancer 刚开始没看懂,题目,后来才慢慢看懂的, 题目要求,用最少的矩形框填充空白的地方 var grid = this. ...

  3. 【详解】Dubbo的原理以及详细原理、配置

    Dubbo的背景 随着互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及流动计算架构势在必行,亟需一个治理系统确保架构有条不紊的演进. Dubbo的应用 用于大规模 ...

  4. UVa 11134 传说中的车

    https://vjudge.net/problem/UVA-11134 题意:在n*n的棋盘上放n个车,使得任意两个车不相互攻击,且第i个车在一个给定的矩形Ri之内.用4个整数xli,yli,xri ...

  5. 警告:Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA

    加入 import os os.environ[' demo: import os os.environ[' import tensorflow as tf tf.enable_eager_execu ...

  6. ros 使用命令测试topic

    发布话题 $ rostopic pub -r /chatter std_msgs/String "test" 输出数据: $ rostopic echo /chatter data ...

  7. python学习——大文件分割与合并

    在平常的生活中,我们会遇到下面这样的情况: 你下载了一个比较大型的游戏(假设有10G),现在想跟你的同学一起玩,你需要把这个游戏拷贝给他. 然后现在有一个问题是文件太大(我们不考虑你有移动硬盘什么的情 ...

  8. mysql 开启远程访问

    # vi /etc/mysql/my.cnf修改 bind-address = 127.0.0.1  为  bind-address = 0.0.0.0 修改完成后重启mysql服务 # sudo / ...

  9. ubuntu server 无线网卡的处理

    1) iwconfig 确定一下接口的名称 2) 编辑 /etc/network/interfaces 加入下面的代码 auto wlan0 iface wlan0 inet dhcp wpa-ssi ...

  10. php--------对象(object) 与 数组(array) 的转换

    php开发中常常用到数组,sql数据都是数组,数组和对象用的也是比较多的,常常相互转化,数组是PHP的灵魂,非常强大,面向对象编程也是挺方便的. /** * 数组 转 对象 * * @param ar ...