iOS调用各大地图APP导航,进行路线规划

最近收到了这么一个需求,就是支持目前主流的地图APP导航,也就是说跳转至第三方应用。说实在的一开始我是拒绝的,不过最后还是做了,全是体力活,为了方便大家,我就终结一下,以供参考:

首先是判断APP是否安装代码如下:

[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"iosamap://"]

然后就是添加各个地图APP的白名单:

百度地图:baidumap:

高德地图:iosamap:

腾讯地图:qqmap:

谷歌地图:comgooglemapsurl:

系统地图就不用这么麻烦了,直接这样就好:

CLLocationCoordinate2D endCoor =坐标;        

MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];

 MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:endCoor addressDictionary:nil]];

toLocation.name = [NSString stringWithFormat:@" %@", 目的地];

 [MKMapItem openMapsWithItems:@[currentLocation, toLocation]

                       launchOptions:@{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving,MKLaunchOptionsShowsTrafficKey: [NSNumber numberWithBool:YES]}];

其他地图的打开如下:

百度地图:

NSString *stringURL = [NSString stringWithFormat:@"baidumap://map/direction?origin=%f,%f&destination=%f,%f&mode=driving",user.userLocCoord2D.latitude, user.userLocCoord2D.longitude,

                               目的地.latitude, 目的地.longitude];

[[UIApplication sharedApplication] openURL:url]


高德地图:

NSString *urlString = [[NSString stringWithFormat:@"iosamap://path?sourceApplication=%@&backScheme=%@&sname=%@&dname=%@&dev=0&m=0&t=0&sid=BGVIS1&did=BGVIS2&dlat=%lf&dlon=%lf",@"APP名称", @"iosamap", @"我的位置",目的地,endCoor.latitude, endCoor.longitude] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

[[UIApplication sharedApplication]openURL:[NSURL URLWithString:urlString]];

腾讯地图:

NSString *urlString =[[NSString stringWithFormat:@"qqmap://map/routeplan?type=drive&from=我的位置&to=%@&tocoord=%lf,%lf&policy=1&referer=tengxun",目的地,endCoor.latitude,endCoor.longitude] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];


谷歌地图:(国内谷歌地图无法访问得要轮子哦)

NSString *urlString = [[NSString stringWithFormat:@"comgooglemapsurl://www.google.com/maps/preview/@%lf,%lf,6z",endCoor.latitude, endCoor.longitude] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

 [[UIApplication sharedApplication]openURL:[NSURL URLWithString:urlString]];



以上就是了,至于对应的链接,当时忘记记录了,建议使用谷歌搜一下,都可以看到。




  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值