首页 > 其他分享 >ios打开第三方地图app

ios打开第三方地图app

时间:2023-02-13 17:13:27浏览次数:38  
标签:URLWithString 地图 App ios 第三方 break NSURL app sharedApplication

https://www.jianshu.com/p/691dd39cb28c

 

【ios调起 地图app】分三步:

1、配置相对于地图app的LSApplicationQueriesSchemes白名单

  • 百度地图:baidumap
  • 高德地图:iosamap
  • 腾讯地图:qqmap
  • 苹果地图:http://maps.apple.com/

2.判断是否能打开第三方地图

    //判断是否能打开百度地图
    NSURL * baidu_App = [NSURL URLWithString:@"baidumap://"];
    if ([[UIApplication sharedApplication] canOpenURL:baidu_App]) {
        
     }

    //判断是否能打开高德地图
    NSURL * gaode_App = [NSURL URLWithString:@"iosamap://"];
    if ([[UIApplication sharedApplication] canOpenURL:gaode_App]) {

    }

    //判断是否能打开苹果地图
    NSURL * apple_App = [NSURL URLWithString:@"http://maps.apple.com/"];
    if ([[UIApplication sharedApplication] canOpenURL:apple_App]) {
        [alert addAction:appleAction];
    }

3.传经纬度调起地图导航

  • 百度地图
        NSURL * baidu_App = [NSURL URLWithString:@"baidumap://"];
        if ([[UIApplication sharedApplication] canOpenURL:baidu_App]) {
            // 如果集成的是百度地图就需要用bd09ll否则gcj02
            bdString = [[NSString stringWithFormat:@"baidumap://map/direction?origin={{我的位置}}&destination=latlng:%@,%@|name:%@&coord_type=bd09ll&mode=driving&src=ios.blackfish.XHY",Latitude,Longitude,adderss] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:bdString] options:@{} completionHandler:nil];
        }
  • 高德地图
  •     NSURL * gaode_App = [NSURL URLWithString:@"iosamap://"];
        if ([[UIApplication sharedApplication] canOpenURL:gaode_App]) {
            
            //将BD-09坐标系转换为GCJ-02坐标系
            CLLocationCoordinate2D location = [JZLocationConverter bd09ToGcj02:CLLocationCoordinate2DMake([Latitude doubleValue], [Longitude doubleValue])];
            
            gdString = [[NSString stringWithFormat:@"iosamap://path?sourceApplication=ios.blackfish.XHY&dlat=%f&dlon=%f&dname=%@&style=2&dev=0",latitude,longitude,adderss] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; //先出现地点位置,然后再手动点击导航
        }

     

  • 腾讯地图
  • 可考虑
  • //调起腾讯地图APP,并在图上标注位置 qqmap://map/marker?marker=coord:39.892326,116.342763;title:超好吃冰激凌;addr:手帕口桥北铁路道口&referer=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77
//腾讯地图
- (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) {

    }];
}

 

  • 苹果地图
  •     NSURL * apple_App = [NSURL URLWithString:@"http://maps.apple.com/"];
        if ([[UIApplication sharedApplication] canOpenURL:apple_App]) {
            //将BD-09坐标系转换为GCJ-02坐标系
            CLLocationCoordinate2D location = [JZLocationConverter bd09ToGcj02:CLLocationCoordinate2DMake([Latitude doubleValue], [Longitude doubleValue])];
            
            MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];
            MKMapItem *tolocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:location addressDictionary:nil]];
            tolocation.name = adderss;
            [MKMapItem openMapsWithItems:@[currentLocation,tolocation] launchOptions:@{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving,
                                                                                       MKLaunchOptionsShowsTrafficKey:[NSNumber numberWithBool:YES]}];
        }

     

拓展:

安卓调用

if(outSysType == 10504){// 安卓  10504
                    switch(mapType) {
                      case 'tecentMap':
                          url = 'qqmap://map/routeplan?type=drive&from=&fromcoord=&to='+ title +'&tocoord=' + lat + ',' + lng + '&policy=0&referer=kgjhapp';
                          break;
                      case 'gaodeMap':
                          url = 'androidamap://route?sourceApplication=appName&slat=&slon=&sname=&dlat='+ lat + '&dlon='+ lng+'&dname='+title+'&dev=0&t=2';
                          break;
                      case 'baiduMap':
                          url = 'bdapp://map/direction?destination='+lat+','+lng+'&coord_type=gcj02&mode=driving&src=com.knssshy.sj';
                          break;
                      default:
                          break;
                    }
                  }

 H5调用

  switch(mapType) {
                          case 'tecentMap':
                              url = 'https://apis.map.qq.com/uri/v1/marker?marker=coord:' + lat + ',' +  lng +';addr:'+ address +';title:'+ title + '&referer=keyfree';
                              break;
                          case 'gaodeMap':
                              url = 'https://uri.amap.com/marker?position='+ lng + ',' + lat +'&name='+ address +'&callnative=1';
                              break;
                          case 'baiduMap':
                              url = 'http://api.map.baidu.com/marker?location=' + lat + ',' +  lng +'&title='+ title + '&content='+ address +'&output=html&src=webapp.reformer.appname&coord_type=gcj02';
                              break;
                          default:
                              break;
                      }

 

标签:URLWithString,地图,App,ios,第三方,break,NSURL,app,sharedApplication
From: https://www.cnblogs.com/haoran5544/p/17116828.html

相关文章

  • springboot 读取配置 application.yml
    添加配配置信息spring:application:name:dataExChangePlatformdevtools:restart:enabled:trueadditional-paths:src/main/javae......
  • MobPush 助力工具 APP 激活用户,留存率提升 31%
    近几年里,吸引用户注意力的争夺在内容资讯行业十分激烈。在此背景下,能吸引用户注意力,能够高效连接内容与用户的APP将发挥出更大的增长潜力。近期,某工具APP与MobTech携......
  • uniapp 小程序引流关注公众号
    official-account组件说明:微信公众号关注组件。当用户扫小程序码打开小程序时,开发者可在小程序内配置公众号关注组件,方便用户快捷关注公众号,可嵌套在原生组件内。仅微信......
  • axios的第二种写法,把请求路径抽离到一个文件
    utils/http.jsimportaxiosfrom'axios';importqsfrom'qs';import{VALID_LOGIN}from'_config/url'importcontextfrom'../main.js'importrouterfrom'........
  • uni-app:使用uni-list显示列表数据之一(hbuilderx 3.6.18)
    一,演示代码:说明:演示代码中实现的功能:    1,各个列表项展示不同类型的内容    2,取消uni-list-item默认样式中的padding    3,  取消uni-list......
  • [Error] a template declaration cannot appear at block scope
    测试C++11中  AliasTemplate时出现出现报错程序:#include<iostream>#include<vector>usingnamespacestd;intmain(){ template<typenameT> usingVec......
  • APP性能测试
    adb命令查看手机使用情况adbshelldumpsys[options]options:meminfo显示内存信息cpuinfo显示cpu信息wifi显示wifi信息activity显......
  • windows 下安装wda 到ios手机上
    首先找到了一个已经编译好的wda安装包(网上确实有这样的,有的开源项目自带的单测里有记录这个包,比如这个地方:[https://github.com/alibaba/taobao-iphone-device/blob/7ba9......
  • NATAPP使用教程(内网穿透)
    NATAPP使用教程(内网穿透)https://blog.csdn.net/weixin_42601136/article/details/108836388 内网穿透(NATAPP)简易使用(!!!用这条链接最准确)https://betheme.net/news/txtli......
  • uniapp小程序端实现身份证相机
    template:<template><view><!--选择相机拍照--><viewclass="container"><!--相机--><!--初始showcamer......