iOS跳转到第三地图导航

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

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

iOS跳转到第三地图导航_第1张图片
Snip20161024_1.png

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

LSApplicationQueriesSchemes

        baidumap //百度地图
        iosamap//高德地图
        comgooglemaps//谷歌地图
        qqmap//腾讯地图
    

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

效果图如下

iOS跳转到第三地图导航_第2张图片
Snip20161024_2.png

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

你可能感兴趣的:(iOS跳转到第三地图导航)