ios打开第三方地图app

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;
                      }

 

posted @ 2023-02-13 17:01  高sir不会跳舞  阅读(242)  评论(0编辑  收藏  举报