iOS跳转到第三地图导航

作者: iOS_ZG | 来源:发表于2016-10-22 11:56 被阅读189次

跳转到第三方应用必须先设置Scheme 白名单

1.打开info.plist 如下图设置

Snip20161024_1.png

也可以通过info.plist->open As -> Source Code 设置LSApplicationQueriesSchemes

<key>LSApplicationQueriesSchemes</key>
<array>
        <string>baidumap</string> //百度地图
        <string>iosamap</string>//高德地图
        <string>comgooglemaps</string>//谷歌地图
        <string>qqmap</string>//腾讯地图
    </array>

2.获取手机地图应用


#pragma mark -导航方法

+ (NSArray*)getInstalledMapAppWithEndLocation:(CLLocationCoordinate2D)endLocation withAddress:(NSString*)address

{

NSMutableArray*maps = [NSMutableArrayarray];

//苹果地图

NSMutableDictionary*iosMapDic = [NSMutableDictionarydictionary];

iosMapDic[@"title"] =@"苹果地图";

[mapsaddObject:iosMapDic];

//百度地图

if([[UIApplicationsharedApplication]canOpenURL:[NSURLURLWithString:@"baidumap://"]]) {

NSMutableDictionary*baiduMapDic = [NSMutableDictionarydictionary];

baiduMapDic[@"title"] =@"百度地图";

NSString*urlString = [[NSStringstringWithFormat:@"baidumap://map/direction?origin={{我的位置}}&destination=latlng:%f,%f|name=北京&mode=driving&coord_type=gcj02",endLocation.latitude,endLocation.longitude]stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSetURLQueryAllowedCharacterSet]];

baiduMapDic[@"url"] = urlString;

[mapsaddObject:baiduMapDic];

}

//高德地图

if([[UIApplicationsharedApplication]canOpenURL:[NSURLURLWithString:@"iosamap://"]]) {

NSMutableDictionary*gaodeMapDic = [NSMutableDictionarydictionary];

gaodeMapDic[@"title"] =@"高德地图";

NSString*urlString = [[NSStringstringWithFormat:@"iosamap://navi?sourceApplication=%@&backScheme=%@&poiname=%@&poiid=BGVIS&lat=%f&lon=%f&dev=1&style=2",applicationName,applicationScheme,address,endLocation.latitude,endLocation.longitude]stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSetURLQueryAllowedCharacterSet]];

gaodeMapDic[@"url"] = urlString;

[mapsaddObject:gaodeMapDic];

}

//谷歌地图

if([[UIApplicationsharedApplication]canOpenURL:[NSURLURLWithString:@"comgooglemaps://"]]) {

NSMutableDictionary*googleMapDic = [NSMutableDictionarydictionary];

googleMapDic[@"title"] =@"谷歌地图";

NSString*urlString = [[NSStringstringWithFormat:@"comgooglemaps://?x-source=%@&x-success=%@&saddr=&daddr=%f,%f&directionsmode=driving",@"导航测试",@"nav123456",endLocation.latitude, endLocation.longitude]stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSetURLQueryAllowedCharacterSet]];

googleMapDic[@"url"] = urlString;

[mapsaddObject:googleMapDic];

}

//腾讯地图

if([[UIApplicationsharedApplication]canOpenURL:[NSURLURLWithString:@"qqmap://"]]) {

NSMutableDictionary*qqMapDic = [NSMutableDictionarydictionary];

qqMapDic[@"title"] =@"腾讯地图";

NSString*urlString = [[NSStringstringWithFormat:@"qqmap://map/routeplan?from=我的位置&type=drive&tocoord=%f,%f&to=终点&coord_type=1&policy=0",endLocation.latitude, endLocation.longitude]stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSetURLQueryAllowedCharacterSet]];

qqMapDic[@"url"] = urlString;

[mapsaddObject:qqMapDic];

}

returnmaps;

}

3.使用系统actionSheet 弹出展示

UIAlertControllerStyleActionSheet];
    for (int i = 0 ;i<maps.count;i++) {
        NSDictionary *dict = maps[i];
        NSString *title = dict[@"title"];
        if (i==0) {
            UIAlertAction *action = [UIAlertAction actionWithTitle:title style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                [self navAppleMapWith:endLocation];
            }];
            [sheet addAction:action];
        }else{
        NSString *urlString= dict[@"url"];
        UIAlertAction *action = [UIAlertAction actionWithTitle:title style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
        }];
        [sheet addAction:action];

    }
    }
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    [sheet addAction:cancel];
    
    [viewController  presentViewController:sheet animated:YES completion:nil];

效果图如下

Snip20161024_2.png

附上github的Demo 你可以直接下载使用 https://github.com/iOScoderZG/navDemo

相关文章

  • 地图导航

    URI跳转方式地图导航的代码实践iOS调用第三方地图路线导航IOS实现应用内打开第三方地图app进行导航 高德 i...

  • iOS跳转第三方地图导航

    在iOS开发应用过程中,会遇到跳转第三方应用地图进行导航的场景,例如跳转到高德地图,百度地图.如图所示 首先,如果...

  • 2019-03-26

    iOS 调起第三方地图导航

  • Android Kotlin 跳转第三方地图App进行导航(高德

    跳转第三方地图App进行导航 /** * type * 1 高德地图com.autonavi.minimap *...

  • iOS 集成高德地图

    参考文档:iOS 跳转方式实现地图导航功能 应用内导航 是指使用地图服务提供的SDK(比如高德,百度等等),直接将...

  • iOS在应用内跳转第三方导航

    最近做到这个需求要求应用内用户导航时根据手机手机内安装的地图来选择什么地图进行跳转到第三方地图导航功能。这个功能实...

  • IOS地图定位导航

    title : IOS地图定位导航category : UI 地图定位导航 标签(空格分隔): IOS 概述 I...

  • RN-地图导航

    调起百度网页地图路径导航 调起高德网页地图路径导航 iOS调起百度APP地图路径导航 iOS调起高德app地图路径...

  • iOS APP之间的相互跳转

    APP跳转应用场景 比如现在普及的第三方登录分享地图导航,都需要跳转到指定的APP; 原理:通过设置跳转到应用B的...

  • iOS开发-模态视图跳转

    iOS开发中界面的跳转一般都会使用导航栏UINavigationController来进行push跳转,使用导航栏...

网友评论

    本文标题:iOS跳转到第三地图导航

    本文链接:https://www.haomeiwen.com/subject/wbfhuttx.html