iOS 调用第三方应用地图 笔记

    NSString *address = dic[@"address"]; // 目标地址
    
    if (type == 0) { // 百度地图

        NSString *urlString = [[NSString stringWithFormat:@"baidumap://map/direction?origin={{我的位置}}&destination=%@&mode=riding&src=趣Bar",address] stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLQueryAllowedCharacterSet];
        NSURL *url = [NSURL URLWithString:urlString];
        [[UIApplication sharedApplication] openURL:url];
        
    }else if (type == 1) { // 高德地图
        
        NSString *urlString = [[NSString stringWithFormat:@"iosamap://path?sourceApplication=趣Bar&sid=BGVIS1&sname=%@&did=BGVIS2&dname=%@&dev=0&t=0",@"我的位置",address] stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLQueryAllowedCharacterSet];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
        
    }else if (type == 2) { // 苹果地图
        
        NSString *urlString = [[NSString stringWithFormat:@"http://maps.apple.com/?daddr=%@",address] stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLQueryAllowedCharacterSet];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
        
    }

你可能感兴趣的:(iOS 调用第三方应用地图 笔记)