美文网首页
ios地图导航模块(跳转苹果自带地图,高德地图,百度地图)

ios地图导航模块(跳转苹果自带地图,高德地图,百度地图)

作者: Buger123 | 来源:发表于2019-04-17 14:08 被阅读0次

1、plist白名单设置

plist文件新增LSApplicationQueriesSchemes关键字,类型为NSArray,并在其下添加子目录,类型为NSString,内容为各地图对应的url Scheme。

2、跳转到相应app

- (void)skipToApps {//苹果自带地图    NSURL *scheme = [NSURL URLWithString:@"http://maps.apple.com/"];        BOOL canOpen = [[UIApplication sharedApplication] canOpenURL:scheme];        if (canOpen) {                MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];        MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:self.coordinate addressDictionary:self.addressDictionary]];                toLocation.name = self.name;        [MKMapItem openMapsWithItems:@[currentLocation, toLocation]                       launchOptions:  @{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving,    MKLaunchOptionsMapTypeKey:@(MKMapTypeStandard),    MKLaunchOptionsShowsTrafficKey: [NSNumber numberWithBool:YES]}         ];    } else {        [MBProgressHUD showMessage:@"手机未安装地图" toView:self.view.superview];    }}

- (void)skipToIosamapApps {//判断高德        NSURL *scheme = [NSURL URLWithString:@"iosamap://"];        BOOL canOpen = [[UIApplication sharedApplication] canOpenURL:scheme];        if (canOpen) {        NSString *str = [NSString stringWithFormat:@"iosamap://navi?sourceApplication=applicationName&poiname=fangheng&poiid=BGVIS&lat=%@&lon=%@&dev=1&style=2",[NSString stringWithFormat:@"%f",self.coordinate.latitude],[NSString stringWithFormat:@"%f",self.coordinate.longitude]];                NSURL *myLocationScheme = [NSURL URLWithString:str];                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];        }    } else {         [MBProgressHUD showMessage:@"手机未安装高德地图" toView:self.view.superview];    }}

- (void)skipToBaidumapApps {//百度地图    NSURL *scheme = [NSURL URLWithString:@"baidumap://"];        BOOL canOpen = [[UIApplication sharedApplication] canOpenURL:scheme];        if (canOpen){        NSString *str =[[NSString stringWithFormat:@"baidumap://map/direction?origin={{我的位置}}&destination=latlng:%f,%f|name=%@&mode=driving&coord_type=gcj02",self.coordinate.latitude,self.coordinate.longitude,self.name] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];                NSURL *myLocationScheme = [NSURL URLWithString:str];                [[UIApplication sharedApplication] openURL:myLocationScheme options:@{} completionHandler:^(BOOL success) {                    }];    } else {        [MBProgressHUD showMessage:@"手机未安装百度地图" toView:self.view.superview];    }}

self.coordinate通过传入地址名称,地理编码获取

相关文章

网友评论

      本文标题:ios地图导航模块(跳转苹果自带地图,高德地图,百度地图)

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