应用跳转第三方代码

BOOL ISGaoDeMap= [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"iosamap://"]];
BOOL ISBaiduMap= [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"baidumap://"]];
BOOL ISGugeMap= [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"comgooglemaps://"]];
BOOL ISTengxunMap= [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"qqmap://"]];
NSLog(@"高德地图:%d,百度地图:%d,谷歌地图:%d,腾讯地图:%d",ISGaoDeMap,ISBaiduMap,ISGugeMap,ISTengxunMap);
NSArray *addressArr=[self.deviceMD.deviceAddressArrJSStr mj_JSONObject];
NSString *latitude=[[addressArr firstObject] objectForKey:@"latitude"];
NSString *longitude=[[addressArr firstObject] objectForKey:@"longitude"];
if ([self.deviceMD.connectStatus isEqualToString:@"connect"]) {
//连接状态
latitude=[NSString stringWithFormat:@"%f",_deviceLa];
longitude=[NSString stringWithFormat:@"%f",_deviceLo];
}

CLLocationCoordinate2D bd09Coord = CLLocationCoordinate2DMake([latitude doubleValue], [longitude doubleValue]);
// 转为百度经纬度类型的坐标
CLLocationCoordinate2D gcj02Coord = BMKCoordTrans(bd09Coord, BMK_COORDTYPE_BD09LL, BMK_COORDTYPE_COMMON);

CLLocationCoordinate2D gaodecoord = BMKCoordTrans(bd09Coord, BMK_COORDTYPE_BD09LL, BMK_COORDTYPE_COMMON);

NSLog(@"定位百度原始坐标:%@---%@",latitude,longitude);
NSLog(@"定位bd09Coord坐标:%f---%f",bd09Coord.latitude,bd09Coord.longitude);
NSLog(@"定位gaodecoord坐标:%f---%f",gaodecoord.latitude,gaodecoord.longitude);

// CLLocationCoordinate2D gaodecoord = AMapCoordinateConvert(CLLocationCoordinate2DMake(gpscoord.latitude,gpscoord.longitude), AMapCoordinateTypeAMap);

NSArray *mapStrArr=@[@"高德地图",@"百度地图",@"谷歌地图",@"腾讯地图"];
NSMutableArray *statusArr=[NSMutableArray array];
[statusArr addObject:[NSString stringWithFormat:@"%d",ISGaoDeMap]];
[statusArr addObject:[NSString stringWithFormat:@"%d",ISBaiduMap]];
[statusArr addObject:[NSString stringWithFormat:@"%d",ISGugeMap]];
[statusArr addObject:[NSString stringWithFormat:@"%d",ISTengxunMap]];
NSMutableArray *mapArr=[NSMutableArray array];
[mapArr addObject:@"本机地图"];
for (int i=0; i<mapStrArr.count; i++) {
    NSString *tempStr=statusArr[i];
    if ([tempStr isEqualToString:@"1"]) {
        [mapArr addObject:mapStrArr[i]];
    }
}

NSArray *colorArr = @[kTextColor333333,kTextColor333333,kTextColor333333,kTextColor333333,kTextColor333333,];
[self.view createAlertViewTitleArray:mapArr textColor:colorArr font:[UIFont systemFontOfSize:18] actionBlock:^(UIButton * _Nullable button, NSInteger didRow) {
    //获取点击事件
    NSLog(@"%@,%ld",button.currentTitle,(long)didRow);
    NSString* didRowStr = [NSString stringWithFormat:@"%ld",(long)didRow];
    if ([didRowStr isEqualToString:@"0"]) {//本机地图
        
        CLLocationCoordinate2D loc = CLLocationCoordinate2DMake(gcj02Coord.latitude, gcj02Coord.longitude);
        MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];
        MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:loc addressDictionary:nil]];
        toLocation.name = [NSString stringWithFormat:@"%@",[[addressArr firstObject] objectForKey:@"address"]];
        [MKMapItem openMapsWithItems:@[currentLocation, toLocation]
                           launchOptions:@{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving,
                                           MKLaunchOptionsShowsTrafficKey: [NSNumber numberWithBool:YES]}];
        
    }else if ([didRowStr isEqualToString:@"1"]){//百度地图
        if ([button.currentTitle isEqualToString:@"百度地图"]) {
            NSString *urlString = [[NSString stringWithFormat:@"baidumap://map/direction?origin={{我的位置}}&destination=latlng:%f,%f|name=目的地&mode=driving&coord_type=bd09ll",[latitude doubleValue], [longitude doubleValue]] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
        }else if ([button.currentTitle isEqualToString:@"高德地图"]){
            NSString *urlString = [NSString stringWithFormat:@"iosamap://path?sourceApplication=jikexiue&backScheme=jkxe&slat=&slon=&sname=我的位置&dev=1&t=0"];
                
            urlString = [NSString stringWithFormat:@"%@&dlat=%f&dlon=%f&dname=%@",urlString, gaodecoord.latitude, gaodecoord.longitude, [[addressArr firstObject] objectForKey:@"address"]];
                
            urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

// urlString =[urlString stringByAddingPercentEncodingWithAllowedCharacters:[[NSCharacterSet characterSetWithCharactersInString:@"?!@#$^&%*+,:;='"`<>()[]{}/\| "] invertedSet]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{} completionHandler:^(BOOL success) {

            }];
            
            
        }else if ([button.currentTitle isEqualToString:@"谷歌地图"]){

// NSString *str = [NSString stringWithFormat:@"comgooglemaps://?x-source=%@&x-success=%@&saddr=&daddr=%f,%f&directionsmode=driving",@"滴滴地图",@"91ailishi",gcj02Coord.latitude, gcj02Coord.longitude];
// [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
NSString *urlString = [[NSString stringWithFormat:@"comgooglemaps://?x-source=%@&x-success=%@&saddr=&daddr=%f,%f&directionsmode=driving",@"滴滴地图",@"91ailishi",gcj02Coord.latitude, gcj02Coord.longitude] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{} completionHandler:nil];

        }else if ([button.currentTitle isEqualToString:@"腾讯地图"]){
            NSString *urlString = [NSString stringWithFormat:@"qqmap://map/routeplan?type=drive&fromcoord=,&from=我的位置&referer=jikexiu"];
                urlString = [NSString stringWithFormat:@"%@&tocoord=%f,%f&to=%@",urlString, gcj02Coord.latitude, gcj02Coord.longitude, [[addressArr firstObject] objectForKey:@"address"]];
                urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{} completionHandler:^(BOOL success) {
                    
                }];
        }
        
    }else if ([didRowStr isEqualToString:@"2"]){//百度地图
        if ([button.currentTitle isEqualToString:@"百度地图"]) {
            NSString *urlString = [[NSString stringWithFormat:@"baidumap://map/direction?origin={{我的位置}}&destination=latlng:%f,%f|name=目的地&mode=driving&coord_type=bd09ll",[latitude doubleValue], [longitude doubleValue]] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
        }else if ([button.currentTitle isEqualToString:@"高德地图"]){
            NSString *urlString = [NSString stringWithFormat:@"iosamap://path?sourceApplication=jikexiue&backScheme=jkxe&slat=&slon=&sname=我的位置&dev=1&t=0"];
                
            urlString = [NSString stringWithFormat:@"%@&dlat=%f&dlon=%f&dname=%@",urlString, gaodecoord.latitude, gaodecoord.longitude, [[addressArr firstObject] objectForKey:@"address"]];
                
            urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{} completionHandler:^(BOOL success) {
                
            }];
            
        }else if ([button.currentTitle isEqualToString:@"谷歌地图"]){

// NSString *str = [NSString stringWithFormat:@"comgooglemaps://?x-source=%@&x-success=%@&saddr=&daddr=%f,%f&directionsmode=driving",@"滴滴地图",@"91ailishi",gcj02Coord.latitude, gcj02Coord.longitude];
// [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
NSString *urlString = [[NSString stringWithFormat:@"comgooglemaps://?x-source=%@&x-success=%@&saddr=&daddr=%f,%f&directionsmode=driving",@"滴滴地图",@"91ailishi",gcj02Coord.latitude, gcj02Coord.longitude] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{} completionHandler:nil];

        }else if ([button.currentTitle isEqualToString:@"腾讯地图"]){
            NSString *urlString = [NSString stringWithFormat:@"qqmap://map/routeplan?type=drive&fromcoord=,&from=我的位置&referer=jikexiu"];
                urlString = [NSString stringWithFormat:@"%@&tocoord=%f,%f&to=%@",urlString, gcj02Coord.latitude, gcj02Coord.longitude, [[addressArr firstObject] objectForKey:@"address"]];
                urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{} completionHandler:^(BOOL success) {
                    
                }];
        }
    }else if ([didRowStr isEqualToString:@"3"]){//百度地图
        if ([button.currentTitle isEqualToString:@"百度地图"]) {
            NSString *urlString = [[NSString stringWithFormat:@"baidumap://map/direction?origin={{我的位置}}&destination=latlng:%f,%f|name=目的地&mode=driving&coord_type=bd09ll",[latitude doubleValue], [longitude doubleValue]] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
        }else if ([button.currentTitle isEqualToString:@"高德地图"]){
            NSString *urlString = [NSString stringWithFormat:@"iosamap://path?sourceApplication=jikexiue&backScheme=jkxe&slat=&slon=&sname=我的位置&dev=1&t=0"];
                
            urlString = [NSString stringWithFormat:@"%@&dlat=%f&dlon=%f&dname=%@",urlString, gaodecoord.latitude, gaodecoord.longitude, [[addressArr firstObject] objectForKey:@"address"]];
                
            urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{} completionHandler:^(BOOL success) {
                
            }];
            
        }else if ([button.currentTitle isEqualToString:@"谷歌地图"]){

// NSString *str = [NSString stringWithFormat:@"comgooglemaps://?x-source=%@&x-success=%@&saddr=&daddr=%f,%f&directionsmode=driving",@"滴滴地图",@"91ailishi",gcj02Coord.latitude, gcj02Coord.longitude];
// [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];

            NSString *urlString = [[NSString stringWithFormat:@"comgooglemaps://?x-source=%@&x-success=%@&saddr=&daddr=%f,%f&directionsmode=driving",@"滴滴地图",@"91ailishi",gcj02Coord.latitude, gcj02Coord.longitude] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{} completionHandler:nil];
            
        }else if ([button.currentTitle isEqualToString:@"腾讯地图"]){
            NSString *urlString = [NSString stringWithFormat:@"qqmap://map/routeplan?type=drive&fromcoord=,&from=我的位置&referer=jikexiu"];
                urlString = [NSString stringWithFormat:@"%@&tocoord=%f,%f&to=%@",urlString, gcj02Coord.latitude, gcj02Coord.longitude, [[addressArr firstObject] objectForKey:@"address"]];
                urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{} completionHandler:^(BOOL success) {
                    
                }];
        }
    }else if ([didRowStr isEqualToString:@"4"]){//百度地图
        if ([button.currentTitle isEqualToString:@"百度地图"]) {
            NSString *urlString = [[NSString stringWithFormat:@"baidumap://map/direction?origin={{我的位置}}&destination=latlng:%f,%f|name=目的地&mode=driving&coord_type=bd09ll",[latitude doubleValue], [longitude doubleValue]] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
        }else if ([button.currentTitle isEqualToString:@"高德地图"]){
            NSString *urlString = [NSString stringWithFormat:@"iosamap://path?sourceApplication=jikexiue&backScheme=jkxe&slat=&slon=&sname=我的位置&dev=1&t=0"];
                
            urlString = [NSString stringWithFormat:@"%@&dlat=%f&dlon=%f&dname=%@",urlString, gaodecoord.latitude, gaodecoord.longitude, [[addressArr firstObject] objectForKey:@"address"]];
                
            urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{} completionHandler:^(BOOL success) {
                
            }];
            
        }else if ([button.currentTitle isEqualToString:@"谷歌地图"]){

// NSString *str = [NSString stringWithFormat:@"comgooglemaps://?x-source=%@&x-success=%@&saddr=&daddr=%f,%f&directionsmode=driving",@"滴滴地图",@"91ailishi",gcj02Coord.latitude, gcj02Coord.longitude];
// [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
NSString *urlString = [[NSString stringWithFormat:@"comgooglemaps://?x-source=%@&x-success=%@&saddr=&daddr=%f,%f&directionsmode=driving",@"滴滴地图",@"91ailishi",gcj02Coord.latitude, gcj02Coord.longitude] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{} completionHandler:nil];

        }else if ([button.currentTitle isEqualToString:@"腾讯地图"]){
            NSString *urlString = [NSString stringWithFormat:@"qqmap://map/routeplan?type=drive&fromcoord=,&from=我的位置&referer=jikexiu"];
                urlString = [NSString stringWithFormat:@"%@&tocoord=%f,%f&to=%@",urlString, gcj02Coord.latitude, gcj02Coord.longitude, [[addressArr firstObject] objectForKey:@"address"]];
                urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{} completionHandler:^(BOOL success) {
                    
                }];
        }
    }
}];
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容