项目里面有位置功能,需要有导航,导航两种实现方式 (集成第三方SDK、URL跳转第三方应用) ,直接集成就不说,下面来说下通过url跳转,

最终效果如如下:

如果手机上安装的有客户端就展示,没有就不展示,文档上面写的很详细的,具体地址如下:

高德地图:https://lbs.amap.com/api/amap-mobile/guide/ios/navi

百度地图:http://lbsyun.baidu.com/index.php?title=uri/api/ios

腾讯地图:http://lbs.qq.com/uri_v1/guide-mobile-navAndRoute.html

国内用的暂时就这些,不过需要注意的是,腾讯地图有一个参数需要注册平台开发者账号才能使用,参数还是必传的,如下图:

具体实现代码如下:

一、添加白名单

二、具体实现代码如下:

-(void)getOpenURL
{
[self getInstalledMapAppWithEndLocation:destinationCoordinate2D];
for (int i = ; i < self.maps.count; i ++) {
NSString *title = [NSString stringWithFormat:@"%@",self.maps[i][@"title"]];
[_titleMaps addObject:title];
}
}
#pragma mark 一键导航
- (IBAction)navigationAction:(id)sender { // 实例方法
LCActionSheet *sheet = [[LCActionSheet alloc] initWithTitle:@"请选择地图"
buttonTitles:_titleMaps
redButtonIndex:-
delegate:self];
[sheet show];
} -(void)actionSheet:(LCActionSheet *)actionSheet didClickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex != -) {
if (buttonIndex == ) {
[self navAppleMap];
return;
}
NSDictionary *dic = self.maps[buttonIndex];
NSString *urlString = dic[@"url"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
}
} //苹果地图
- (void)navAppleMap
{
CLLocationCoordinate2D gps = [JZLocationConverter bd09ToWgs84:destinationCoordinate2D]; MKMapItem *currentLoc = [MKMapItem mapItemForCurrentLocation];
MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:gps addressDictionary:nil]];
NSArray *items = @[currentLoc,toLocation];
NSDictionary *dic = @{
MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeDriving,
MKLaunchOptionsMapTypeKey : @(MKMapTypeStandard),
MKLaunchOptionsShowsTrafficKey : @(YES)
}; [MKMapItem openMapsWithItems:items launchOptions:dic];
} #pragma mark - 导航方法
- (NSArray *)getInstalledMapAppWithEndLocation:(CLLocationCoordinate2D)endLocation
{
//苹果地图
NSMutableDictionary *iosMapDic = [NSMutableDictionary dictionary];
iosMapDic[@"title"] = @"苹果地图";
[self.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=%f,%f&mode=driving&src=webapp.navi.yourCompanyName.yourAppName",endLocation.latitude,endLocation.longitude] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
baiduMapDic[@"url"] = urlString;
[self.maps addObject:baiduMapDic];
} //高德地图
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"iosamap://"]]) {
NSMutableDictionary *gaodeMapDic = [NSMutableDictionary dictionary];
gaodeMapDic[@"title"] = @"高德地图"; NSString *urlString = [[NSString stringWithFormat:@"iosamap://navi?sourceApplication=applicationName&poiname=fangheng&poiid=BGVIS&lat=%f&lon=%f&dev=1&style=2",endLocation.latitude,endLocation.longitude] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
gaodeMapDic[@"url"] = urlString;
[self.maps addObject:gaodeMapDic];
} //腾讯地图
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"qqmap://"]]) {
NSMutableDictionary *qqMapDic = [NSMutableDictionary dictionary];
qqMapDic[@"title"] = @"腾讯地图";
NSString *urlString = [[NSString stringWithFormat:@"qqmap://map/routeplan?type=drive&from=我的位置&to=洗车点&tocoord=%f,%f&referer=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77",endLocation.latitude,endLocation.longitude] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
qqMapDic[@"url"] = urlString;
[self.maps addObject:qqMapDic];
} return self.maps;
}

然后直接调用getOpenURL方法即可,传经纬度是用CLLocationCoordinate2D直接传的,展示用的是大神写好的第三方库:LCActionSheet,上面的代码可以直接使用,亲测有效!如果变动,请以文档为准!

ios开发之--条用第三方地图路线导航的更多相关文章

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

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

  2. iOS开发---集成ShareSDK实现第三方登录、分享、关注等功能。

    (1)官方下载ShareSDK IOS 2.9.6,地址:http://sharesdk.mob.com/Download (2)根据实际情况,引入相关的库,参考官方文档. (3)在项目的AppDel ...

  3. iOS开发那些事-iOS6苹果地图实用开发

    在iOS 6之后,不再使用谷歌地图了,而是使用苹果自己的地图,但是API编程接口没有太大的变化.开发人员不需要再学习很多新东西就能开发地图应用,这是负责任的做法.因此本节介绍的内容也同样适用于iOS5 ...

  4. iOS开发那些事-iOS6苹果地图有用开发

    在iOS 6之后,不再使用谷歌地图了,而是使用苹果自己的地图,可是API编程接口没有太大的变化.开发者不须要再学习非常多新东西就能开发地图应用,这是负责任的做法.因此本节介绍的内容也相同适用于iOS5 ...

  5. iOS开发--整理常用的第三方资源

    一:第三方插件 1:基于响应式编程思想的oc 地址:https://github.com/ReactiveCocoa/ReactiveCocoa 2:hud提示框 地址:https://github. ...

  6. iOS开发中用到的第三方库概览

    前言:记录一下使用过和接触过的第三方库,重要程度与顺序无关 网络请求: AFNetworking:AFNetworking is a delightful networking library for ...

  7. iOS开发 使用Cocoapods管理第三方类库

    每次上github看到一些优秀的代码,总能看到Podfile,也了解是个管理第三方类库的,今天抽时间学习了一下,挺简单的! 作用:      太多  还是复制一下把!!! CocoaPods是什么? ...

  8. iOS开发--即时通讯常用第三方库

    前言 自毕业到现在,从事iOS即时通讯开发已经1年半之久.主要负责Allure开发,目前已上架,可以在苹果商店搜素Allure.Allure模仿微信的交互和设计效果,已经实现微信的大部分功能. 在这里 ...

  9. iOS开发 - 应用内打开第三方应用并传值

    首先说下这个功能, 应该都有接触过. 比方,你下载了一个电子书,然后选择打开方式的时候,可能会看到你手机中已经安装的阅读类App. 或者,你的QQ收到了某个文件,你也能够选择本地的应用来打开. 那这种 ...

随机推荐

  1. Urllib3 库详解

    文档:http://urllib3.readthedocs.io/en/latest/

  2. ES6之数组操作

    es6中对于数组操作添加了4种方法: 1.map —— 映射(一个对应一个) 2.reduce —— 汇总(多个出来一个) 3.filter —— 过滤 4.forEach —— 迭代/循环. 1.m ...

  3. 区分重载(overload),覆盖(Override)和隐藏(hide)

    重载overload,这个概念是大家熟知的.在同一可访问区内被声名的几个具有不同参数列的(参数的类型.个数.顺序不同)同名函数,程序会根据不同的参数列来确定具体调用哪个函数,这种机制就是重载.重载不关 ...

  4. 通过用户名、密码提交的方式搭建私有git服务端

    1. 系统环境 centos git yum -y install git 2).创建属于自己的git库 mkdir /myGit git init --bare xiangyun.git 3). 添 ...

  5. (笔记)Linux下如何查看高CPU占用率线程

    在 Linux 下 top 工具可以显示 cpu 的平均利用率(user,nice,system,idle,iowait,irq,softirq,etc.),可以显示每个 cpu 的利用率.但是无法显 ...

  6. 捋一捋Spring Web的源码思路

    Servlet前提 Java规定了Servlet Container为每一个web app创建一个Servlet Context:而Servlet Context中又包含了诸多Servlet -- 其 ...

  7. PHP + Smarty + html5 构建Wap应用

    一 简介     Smarty是一个PHP编写的模板引擎(template engine),主要用于构建web应用程序的表示层.Smarty的主页是http://www.smarty.net/down ...

  8. e792. 建立一个包括所有数据的SpinnerListModel

    By default, if the user is browsing the values in a SpinnerListModel, the iteration stops when eithe ...

  9. EXP无法导出空表的表结构解决办法

    原文链接:http://www.cnblogs.com/Mr_JinRui/archive/2012/11/05/2755035.html 早的一次使用oracle 11g导出数据发现有的表丢失了,感 ...

  10. http_build_query用法

    http_build_query (PHP 5) http_build_query -- 生成 url-encoded 之后的请求字符串描述string http_build_query ( arra ...