ios html调起高德地图,iOS开发笔记 调起本地地图导航(百度、高德、腾讯、苹果自带)...
地图
从自己的APP跳转到用户本地的APP进行导航。首先,要先查看用户都安装了哪些地图类APP.
下面分3种情况进行分析:
1、用户没有安装第三方的地图,只有苹果自带的地图应用。
2、用户安装一款第三方地图应用。
3、用户安装了超过一款地图应用。
遇到第1、2情况直接跳转应用。第三种情况,需要弹出选项,让用户自主选择。
代码:
//查看线路
- (void)clickLine:(UIButton *)sender{
NSMutableArray *mapArr = [NSMutableArray arrayWithCapacity:0];
if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"baidumap://"]]){
[mapArr addObject:@"百度地图"];
}
if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"iosamap://"]]){
[mapArr addObject:@"高德地图"];
}
if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"qqmap://"]]){
[mapArr addObject:@"腾讯地图"];
}
if (mapArr.count == 1) {
[self JumpToMap:mapArr[0]];
}else if(mapArr.count > 0){
UIAlertController *mapAlert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
for (NSString *mapName in mapArr) {
UIAlertAction *Action = [UIAlertAction actionWithTitle:mapName style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[self JumpToMap:action.title];
}];
[mapAlert addAction:Action];
}
//取消
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}];
[mapAlert addAction:cancelAction];
[self presentViewController:mapAlert animated:YES completion:^{
}];
}else{
//使用自带地图
[self JumpToMap:@"苹果地图"];
}
}
分流函数:
//选择地图
- (void)JumpToMap:(NSString *)mapName{
if ([mapName isEqualToString:@"苹果地图"]) {
[self appleMap];
}else if ([mapName isEqualToString:@"百度地图"]){
[self BaiduMap];
}else if ([mapName isEqualToString:@"高德地图"]){
[self iosMap];
}else if ([mapName isEqualToString:@"腾讯地图"]){
[self qqMap];
}
}
备注:如果兼容ios10以下的应用,跳转请做好适配,ios10以下系统请使用:
- openURL:(NSURL*)url
百度地图
//百度地图
- (void)BaiduMap{
float shopLat = 百度坐标;
float shoplng = 百度坐标;
NSString *urlString = [NSString stringWithFormat:@"baidumap://map/direction?origin=latlng:%f,%f|name:我的位置&mode=transit&coord_type= bd09ll",self.userLocation.location.coordinate.latitude, self.userLocation.location.coordinate.longitude];
if (shopLat != 0 && shoplng != 0) {
urlString = [NSString stringWithFormat:@"%@&destination=latlng:%f,%f|name:%@", urlString, shopLat, shoplng, @"目标地址,你可以自行替换"];
}else{
urlString = [NSString stringWithFormat:@"%@&destination=%@|name:%@",urlString, _orderModel.addressStr,_orderModel.addressStr];
}
urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{} completionHandler:^(BOOL success) {
}];
}
高德地图
//高德地图
- (void)iosMap{
CLLocationCoordinate2D gcj02Coord = CLLocationCoordinate2DMake(百度坐标, 百度坐标);
float shopLat = gcj02Coord.latitude;
float shoplng = gcj02Coord.longitude;
NSString *urlString = [NSString stringWithFormat:@"iosamap://path?sourceApplication=jikexiue&backScheme=jkxe&slat=%f&slon=%f&sname=我的位置&dev=1&t=1",self.userLocation.location.coordinate.latitude, self.userLocation.location.coordinate.longitude];
if (shopLat != 0 && shoplng != 0) {
urlString = [NSString stringWithFormat:@"%@&dlat=%f&dlon=%f&dname=%@", urlString, shopLat, shoplng ,_orderModel.addressStr];
}else{
urlString = [NSString stringWithFormat:@"%@&dname=%@",urlString, _orderModel.addressStr];
}
urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{} completionHandler:^(BOOL success) {
}];
}
腾讯地图
//腾讯地图
- (void)qqMap{
CLLocationCoordinate2D gcj02Coord = CLLocationCoordinate2DMake(百度坐标, 百度坐标);
float shopLat = gcj02Coord.latitude;
float shoplng = gcj02Coord.longitude;
NSString *urlString = [NSString stringWithFormat:@"qqmap://map/routeplan?type=bus&fromcoord=%f,%f&from=我的位置&referer=jikexiu",self.userLocation.location.coordinate.latitude, self.userLocation.location.coordinate.longitude];
urlString = [NSString stringWithFormat:@"%@&tocoord=%f,%f&to=%@",urlString, shopLat, shoplng, _orderModel.addressStr];
urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{} completionHandler:^(BOOL success) {
}];
}
苹果原生地图
1、添加库MapKit.framework
2、引入: #import
//苹果原生地图
- (void)appleMap{
CLLocationCoordinate2D desCoordinate = CLLocationCoordinate2DMake(_orderModel.lat, _orderModel.lng);
MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];
currentLocation.name = @"我的位置";
MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:desCoordinate addressDictionary:nil]];
toLocation.name = [NSString stringWithFormat:@"%@",_orderModel.addressStr];
[MKMapItem openMapsWithItems:@[currentLocation, toLocation]
launchOptions:@{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeTransit,MKLaunchOptionsShowsTrafficKey: [NSNumber numberWithBool:YES]}];
}
ios html调起高德地图,iOS开发笔记 调起本地地图导航(百度、高德、腾讯、苹果自带)...相关推荐
- 【高德地图WEB开发】 入门篇(地图/搜索/经纬度/缩放层级)
前言 本篇文章是高德地图web开发入门篇,实现地图搜索等基本功能,后续会继续更新地图标记点.驾车.骑行.货车等单地点\多地点导航.公交路线.兴趣周边点.及其他地图功能开发文章,所有功能均使用js实现, ...
- 安卓开发笔记(十二)—— 基于百度地图SDK完成地图中心定位,marker转向,动态定位
中山大学数据科学与计算机学院本科生实验报告 (2018年秋季学期) 项目源码:Github传送门 第十七周任务 一.实验题目 地图 第十七周实验目的 接入百度地图API 掌握少量的百度地图API接口 ...
- 高德地图路径轨迹起点标点不变_前有百度高德,后有华为滴滴,腾讯地图该如何上演王者归来的戏码?...
腾讯地图界面(图片来自网络) 文 | 魏启扬 来源 | 智能相对论(ID:aixdlun) BAT的商战大戏是科技圈永不过时的话题. 手机地图的竞争版图中,阿里的高德地图.百度地图两骑绝尘,拥有绝对的 ...
- 高德地图只显示一个省_怎么才能在百度地图腾讯地图高德地图上把一个位置的名称改成自己店铺的名称?...
好处和优势 地图广告:一目了然的超级广告,导航地图:网络地图与搜索引擎的完美组合: 地图标注:与众不同的竞争利器可以使花最少钱得到大的知名度提升及丰厚的销售回报: 客 ...
- Android studio百度地图SDK开发 2020最新超详细的Android 百度地图开发讲解(3) 路线规划步行骑行驾车路线规划
2020最新超详细的Android 百度地图开发讲解(3) 路线规划步行骑行驾车路线规划 开发前配置,显示基本地图,实时定位等查看之前代码,此博客紧接上一博客:https://blog.csdn.ne ...
- baidumap api MySQL_百度地图API开发笔记一(基础篇)
什么是百度地图API? 百度地图API是一套由JavaScript语言编写的应用程序接口,它能够帮助您在网站中构建功能丰富.交互性强的地图应用.百度地图API包含了构建地图基本功能的各种接口,提供了诸 ...
- Android studio百度地图SDK开发 2020最新超详细的Android 百度地图开发讲解(6) POI检索, 根据地址输入提示检索 Sug
POI检索, 根据地址输入提示检索 Sug 参考百度地图官方文档:http://lbsyun.baidu.com/index.php?title=androidsdk/guide/search/sug ...
- android studio百度地图教程,Android studio百度地图SDK开发 2020最新超详细的Android 百度地图开发讲解(4) 路线规划之起始点地址输入实现规划...
实现起始点输入的路线规划 要实现输入起始点的路线规划,需要两个输入框,可以将两个输入框设置在和地图同一个Activity中,也可以新建一个Activity,来实现地址的输入,然后通过页面之间的跳转来传 ...
- 【Unity开发笔记】导入大地图
1. 导入地图图片显示模糊 我导入地图的文件格式为 .psb ,相比起 .psd 格式,它可以显示出多个图层,而不会被压缩到只剩一个图层 2. 地图显示模糊 地图的画布大小是5380*6000,但是导 ...
最新文章
- iOS 9 通用链接(Universal Links)
- PHP和MySQL Web开发从新手到高手,第8天-创建categories管理页面
- php 添加行_php 多行数据同时插入
- asp.net MVC 路由
- 杭州找Android工作的点点滴滴
- 背景和文字分离的matlab实现
- 【洛谷 2330】繁忙的都市
- 15.确保“lessT“与“operator小于“具有相同的语义
- P4451-[国家集训队]整数的lqp拆分【生成函数,特征方程】
- 11月1日上午PHP批量删除
- 30页PPT解析微服务架构与最佳实践
- 给为工作而焦急迷茫的你
- sprig aop事务配置
- Linux网络编程必学的TCP/IP协议——图解分层(通俗易懂)【建议新手收藏】
- 第一届程序设计竞赛题解(G题)
- netware显示没有首选服务器,NetWare下服务器配置几例
- 从链家网上爬取租房数据并进行数据分析
- VMware虚拟机win10系统桥接模式连不上网
- 通过EverEdit工具连接Linux系统远程操作文件
- 金融级湖仓一体架构——SequoiaDB巨杉数据库初探
热门文章
- Frog青蛙的约会【浙江省选2002】(数论)
- Ajax与分页的实现
- SLAM中的李群和李代数
- 非线性方程组求解方法,神经网络的非线性函数
- Markdown使用进阶教程
- 3dsmax顶点死活焊接不上的原因!
- 头条是一款遵循材料设计(Material Design)的第三方今日头条客户端, 聚合了新闻/段子/图片/视频/头条号内容, 没有广告, 仅仅只有存粹的阅读, 不断完善中, 采用 MVP + RxJa
- 查看电脑系统是否永久激活
- 字节 找出最近时间(回溯) C++ 2021-07-17
- 【Scratch二次开发】04-构建离线版本