移动开发经常用到基于位置的一些导航功能,但是对于对导航功能依赖性不强的的应用,我们直接采用应用外跳转地图APP即可。

但是应用间跳转,首先需要设置白名单,

在iOS 9 下涉及到平台客户端跳转,系统会自动到项目info.plist下检测是否设置平台Scheme,对于需要配置的平台,如果没有配置,将无法正常跳转平台客户端,因此需要配置Scheme名单。本文我们需要添加百度地图和高德地图的scheme白名单。

具体方法:在项目的info.plist中添加LSApplicationQueriesSchemes字段,类型是Array,然后添加两个Item。

下面直接上主要代码,网上高德都是直接导航的,为啥?都那么做?

- (void)mapBtnclick{
if (![NSString isNotEmptyString:_currentadress]) {
[self.locationManager startUpdatingLocation];
[SDIndicator showInfoWithMessage:@"正在定位,请稍候..."];
}
_actionSheet= [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:nil];
NSMutableArray *mapsArray=[[NSMutableArray alloc] initWithCapacity:0];
_mapsUrlArray=[[NSMutableArray alloc] init];
NSURL * apple_App = [NSURL URLWithString:@"http://maps.apple.com/"];
if ([[UIApplication sharedApplication] canOpenURL:apple_App]) {
[mapsArray addObject:@"使用苹果自带地图导航"];
NSString *urlString=[NSString stringWithFormat:@"http://maps.apple.com/?saddr=%f,%f&daddr=%f,%f",_strLatitude,_strLongitude,[_model.last_latitude floatValue],[_model.last_longitude floatValue] ];
[_mapsUrlArray addObject:urlString];
} NSURL * baidu_App = [NSURL URLWithString:@"baidumap://"];
if ([[UIApplication sharedApplication] canOpenURL:baidu_App]) {
[mapsArray addObject:@"使用百度地图导航"]; NSString *stringURL =[[NSString stringWithFormat:@"baidumap://map/direction?origin={{我的位置}}&destination=latlng:%f,%f|name=%@&mode=driving&coord_type=gcj02",[_model.last_latitude floatValue],[_model.last_longitude floatValue],_model.address] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[_mapsUrlArray addObject:stringURL]; } NSURL * gaode_App = [NSURL URLWithString:@"iosamap://"];
if ([[UIApplication sharedApplication] canOpenURL:gaode_App]) {
[mapsArray addObject:@"使用高德地图导航"];
NSString *urlString = [[NSString stringWithFormat:@"iosamap://path?sourceApplication=%@&sid=BGVIS1&slat=%f&slon=%f&sname=%@&did=BGVIS2&dlat=%f&dlon=%f&dname=%@&dev=0&t=0",@"龙巅鱼邻",_strLatitude,_strLongitude,_currentadress,[_model.last_latitude floatValue],[_model.last_longitude floatValue],_model.address] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[_mapsUrlArray addObject:urlString]; } for (int x=0; x<mapsArray.count; x++) {
[_actionSheet addButtonWithTitle:[mapsArray objectAtIndex:x]]; } if (_mapsUrlArray.count>0) {
[_actionSheet showInView:self.view.window];
}else{
[SDIndicator showInfoWithMessage:@"建议您安装高德或者百度地图"];
} }

下面说一下,主要的知识点

【1】

使用canOpenURL方法来检测该手机是否安装相应APP

该方法会返回一个BOOL值,当为YES时,表明已安装该APP

【2】

1、苹果自带地图(不需要检测,所以不需要URL Scheme)
2、百度地图 baidumap://
3、高德地图 iosamap://

当然要携带参数的话,就按照各个地图的规则进行传值即可

ByZqk

最新文章

  1. PHP中面向对象的关键字
  2. AngularJS快速入门指南16:Bootstrap
  3. %1 不是有效的Win32应用程序
  4. VS2010的Razor智能感知和语法高亮突然消失
  5. JVM 内存
  6. IO笔记
  7. 2329: [HNOI2011]括号修复 - BZOJ
  8. 针对各主流数据mysql、sqlserver、oracle中文乱码问题。
  9. 第13天 JSTL标签、MVC设计模式、BeanUtils工具类
  10. LeetCode之“链表”:在O(1)时间删除链表节点
  11. PAT1100:Mars Numbers
  12. 在Kali Linux中下载工具Stegsolve
  13. 利用Python通过频谱分析和KNN完成iphone拨号的语音识别
  14. Bash 笔记
  15. windows共享文件分析
  16. 检测到目标URL存在http host头攻击漏洞
  17. perl 入门知识(1)
  18. 2016级算法期末模拟练习赛-D.AlvinZH的序列问题
  19. THINKPHP简单商品查询项目
  20. pig(数据流语言和编译器)学习https://www.w3cschool.cn/apache_pig/apache_pig_execution.html

热门文章

  1. PHP计算两个日期相差的年月日时分秒
  2. (66)zabbix导入/导出配置文件
  3. linux文件属性软硬链接知识
  4. vue-cli3.0相关的坑
  5. MYSQL导入数据:Table XXX doesn&#39;t exist的解决
  6. crm项目之整体内容(一)
  7. stm32独立看门狗实验
  8. python——全局变量&amp;局部变量
  9. 牛客练习赛22 C 简单瞎搞题
  10. SQL_3_表达式、条件语句与运算