iOS 通过调用已安装的地图app进行导航

通过url跳转到已经安装的手机app中进行导航 记得查看经纬度编码哦~

  • 高德
    NSURL *aMapScheme = [NSURL URLWithString:@"iosamap://"];
    BOOL canOpenAMap = [[UIApplication sharedApplication] canOpenURL:aMapScheme];
    NSURL *myLocationScheme = [NSURL URLWithString:[NSString stringWithFormat:@"iosamap://navi?sourceApplication=applicationName&lat=%f&lon=%f&dev=0&style=2",lat,lon]];
    if ([[UIDevice currentDevice].systemVersion integerValue] >= 10) {
        //iOS10以后,使用新API
        [[UIApplication sharedApplication] openURL:myLocationScheme options:@{} completionHandler:^(BOOL success) {
            NSLog(@"scheme调用结束");
        }];
    } else { //iOS10以前,使用旧API
        [[UIApplication sharedApplication] openURL:myLocationScheme];
        
    }

高德官方地址: https://lbs.amap.com/api/amap-mobile/guide/ios/navi

  • 百度
    NSURL *bMapScheme = [NSURL URLWithString:@"baidumap://"];
    BOOL canOpenBMap = [[UIApplication sharedApplication] canOpenURL:bMapScheme];
    NSURL *myLocationScheme = [NSURL URLWithString:[NSString stringWithFormat:@"baidumap://map/navi?location=%f,%f&coord_type=gcj02",lat,lon]];
    
    if ([[UIDevice currentDevice].systemVersion integerValue] >= 10) {
        //iOS10以后,使用新API
        [[UIApplication sharedApplication] openURL:myLocationScheme options:@{} completionHandler:^(BOOL success) {
            NSLog(@"scheme调用结束");
        }];
    } else { //iOS10以前,使用旧API
        [[UIApplication sharedApplication] openURL:myLocationScheme];
        
    }

百度的官方地址: http://lbsyun.baidu.com/index.php?title=uri/api/ios#service-page-anchor7

  • 腾讯
    BOOL canOpenQQMap = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"qqmap://"]];
    NSString *urlStr = [NSString stringWithFormat:@"qqmap://map/routeplan?type=drive&fromcoord=CurrentLocation&tocoord=%f,%f",lat,lon];
    NSURL *r = [NSURL URLWithString:urlStr];
    
    [[UIApplication sharedApplication] openURL:r];
    
    UIAlertAction *QQAction = [UIAlertAction actionWithTitle:@"腾讯地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        NSString *urlStr = [NSString stringWithFormat:@"qqmap://map/routeplan?type=drive&fromcoord=CurrentLocation&tocoord=%f,%f",lat,lon];
        NSURL *r = [NSURL URLWithString:urlStr];
        
        [[UIApplication sharedApplication] openURL:r];
    }];
    

腾讯的官方地址: https://lbs.qq.com/uri_v1/guide-mobile-navAndRoute.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值