码迷,mamicode.com
首页 > 移动开发 > 详细

iOS开发之打开地图应用开启导航

时间:2020-10-13 17:50:39      阅读:46      评论:0      收藏:0      [点我收藏+]

标签:driving   traffic   alt   source   app   ini   mod   utf8   位置   

我们以天安门为终点为例

1、打开苹果原生地图应用导航

CLLocationCoordinate2D loc = CLLocationCoordinate2DMake(39.9096, 116.3972);
    MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];
    MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:loc addressDictionary:nil]];
    [MKMapItem openMapsWithItems:@[currentLocation, toLocation]
                   launchOptions:@{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving,
                                   MKLaunchOptionsShowsTrafficKey: [NSNumber numberWithBool:YES]}];

直接添加此代码,自动跳转到原生地图应用开启导航路线规划

技术图片

2、百度地图开启导航

NSString *urlString = [[NSString stringWithFormat:@"baidumap://map/direction?origin={{我的位置}}&destination=latlng:%f,%f|name=目的地&mode=driving&coord_type=gcj02",39.9096, 116.3972] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];

自动跳转百度地图开启导航

技术图片

3、高德地图

NSString *urlString = [[NSString stringWithFormat:@"iosamap://navi?sourceApplication=%@&backScheme=%@&lat=%f&lon=%f&dev=0&style=2",appName, 39.9096, 116.3972] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];

4、谷歌地图

NSString *urlString = [[NSString stringWithFormat:@"comgooglemaps://?x-source=%@&x-success=%@&saddr=&daddr=%f,%f&directionsmode=driving",appName, 39.9096, 116.3972] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];

 

iOS开发之打开地图应用开启导航

标签:driving   traffic   alt   source   app   ini   mod   utf8   位置   

原文地址:https://www.cnblogs.com/hecanlin/p/13808603.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!