直播平台软件开发之唤起导航软件,实现用户导航
系统定位是直播平台软件开发实现的功能之一,用户在聊天过程中可以互相发送位置信息,查看定位的同时还能进行导航。如果用户想要进行导航的话,需要跳转到三方导航软件,直播平台软件开发是怎样实现的呢?
一、导航功能需求
1.判断是否安装导航软件【高德、百度、腾讯、苹果】;
2.在直播平台软件内打开已安装的导航软件,进行导航;
二、配置白名单
在LSApplicationQueriesSchemes中添加以下信息:
<string>baidumap</string> <string>iosamap</string> <string>qqmap</string>
三、外部调用
[[RKLBSManager shareManager]showNavigationsWithLat:locationContent.latitude lng:locationContent.longitude endName:endName];
四、方法实现
#pragma mark - 打开导航软件开始
-(void)showNavigationsWithLat:(NSNumber *)lat lng:(NSNumber *)lng endName:(NSString *)endName{
UIApplication * app = [UIApplication sharedApplication];
YBWeakSelf;
RKActionSheet *sheet = [[RKActionSheet alloc]initWithTitle:YZMsg(@"")];
if ([app canOpenURL:[NSURL URLWithString:@"iosamap://"]]) {
[sheet addActionWithType:RKSheet_Default andTitle:YZMsg(@"高德地图") complete:^{
[weakSelf openGdMapWithLat:lat lng:lng endName:endName];
}];
}
if ([app canOpenURL:[NSURL URLWithString:@"baidumap://"]]) {
[sheet addActionWithType:RKSheet_Default andTitle:YZMsg(@"百度地图") complete:^{
[weakSelf openBdMapWithLat:lat lng:lng endName:endName];
}];
}
if ([app canOpenURL:[NSURL URLWithString:@"qqmap://"]]) {
[sheet addActionWithType:RKSheet_Default andTitle:YZMsg(@"腾讯地图") complete:^{
[weakSelf openTxMapWithLat:lat lng:lng endName:endName];
}];
}
[sheet addActionWithType:RKSheet_Default andTitle:YZMsg(@"Apple地图") complete:^{
[weakSelf openAppleMapWithLat:lat lng:lng endName:endName];
}];
[sheet addActionWithType:RKSheet_Cancle andTitle:YZMsg(@"取消") complete:^{
}];
[sheet showSheet];
}
/// 高德
-(void)openGdMapWithLat:(NSNumber *)lat lng:(NSNumber *)lng endName:(NSString *)endName{
NSString *appName = [PublicObj getAppName];
NSString *urlString = [[NSString stringWithFormat:@"iosamap://path?sourceApplication=%@&sid=&sname=%@&did=&dlat=%@&dlon=%@&dname=%@&dev=0&t=0",appName,@"我的位置",lat,lng,endName] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{} completionHandler:nil];
}
/// 百度
-(void)openBdMapWithLat:(NSNumber *)lat lng:(NSNumber *)lng endName:(NSString *)endName{
/// 百度需要坐标转换
double old_lat = [lat doubleValue];
double old_lng = [lng doubleValue];
NSArray *newLocA = [self gcjToBd09llLat:old_lat lon:old_lng];
NSNumber *new_lat = newLocA[0];
NSNumber *new_lng = newLocA[1];
NSString *urlString = [[NSString stringWithFormat:@"baidumap://map/direction?origin=&destination=latlng:%@,%@|name:%@&mode=driving&coord_type=bd09ll",new_lat,new_lng,endName] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{} completionHandler:nil];
}
/// 腾讯
-(void)openTxMapWithLat:(NSNumber *)lat lng:(NSNumber *)lng endName:(NSString *)endName{
NSString *appName = [PublicObj getAppName];
NSString *urlString = [[NSString stringWithFormat:@"qqmap://map/routeplan?type=drive&from=我的位置&to=%@&tocoord=%@,%@&policy=1&referer=%@", endName, lat, lng, appName] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
}
/// 苹果地图
-(void)openAppleMapWithLat:(NSNumber *)lat lng:(NSNumber *)lng endName:(NSString *)endName{
float latVal = [NSString stringWithFormat:@"%@", lat].floatValue;
float lngVal = [NSString stringWithFormat:@"%@", lng].floatValue;
CLLocationCoordinate2D loc = CLLocationCoordinate2DMake(latVal, lngVal);
MKMapItem *currentLoc = [MKMapItem mapItemForCurrentLocation];
MKMapItem *toLocation = [[MKMapItem alloc]initWithPlacemark:[[MKPlacemark alloc]initWithCoordinate:loc addressDictionary:nil] ];
toLocation.name = endName;
NSArray *items = @[currentLoc,toLocation];
NSDictionary *dic = @{
MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeDriving,
MKLaunchOptionsMapTypeKey : @(MKMapTypeStandard),
MKLaunchOptionsShowsTrafficKey : @(YES)
};
[MKMapItem openMapsWithItems:items launchOptions:dic];
}
#pragma mark - 打开导航软件结束经过软件配置、方法调用等步骤,直播平台软件开发实现了导航软件跳转,满足用户对导航功能的需求,从细节处优化用户体验。
声明:以上内容为云豹科技原创,未经作者本人同意,禁止转载,否则将追究相关法律责任www.yunbaokj.com






鲁公网安备 37090202000844号

