线路规划:
https://blog.csdn.net/qq_19979539/article/details/51938995
百度地图: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]];
---------------------
作者:尘清_iOS
来源:CSDN
原文:https://blog.csdn.net/qq_19979539/article/details/51938995
目的地导航:
https://www.cnblogs.com/jyking/p/4939637.html
苹果:
1.
NSString *urlString = [[NSString stringWithFormat:@
"http://maps.apple.com/?daddr=%f,%f&saddr=slat,slng"
,coordinate.latitude, coordinate.longitude] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
2.
MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];
MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:nil]];
[MKMapItem openMapsWithItems:@[currentLocation, toLocation]
launchOptions:@{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving,
MKLaunchOptionsShowsTrafficKey: [NSNumber numberWithBool:YES]}];
NSString *urlString = [[NSString stringWithFormat:@
"baidumap://map/direction?origin={{我的位置}}&destination=latlng:%f,%f|name=目的地&mode=driving&coord_type=gcj02"
,coordinate.latitude, coordinate.longitude] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
要注意几点:
1. origin={{我的位置}}
这个是不能被修改的 不然无法把出发位置设置为当前位置
2. destination=latlng:%f,%f|name=目的地
name=XXXX name这个字段不能省略 否则导航会失败 而后面的文字则可以随便填
3. coord_type=gcj02
coord_type允许的值为bd09ll、gcj02、wgs84 如果你APP的地图SDK用的是百度地图SDK 请填bd09ll 否则 就填gcj02 wgs84
NSString *urlString = [[NSString stringWithFormat:@
"iosamap://navi?sourceApplication=%@&backScheme=%@&lat=%f&lon=%f&dev=0&style=2"
,appName,urlScheme,coordinate.latitude, coordinate.longitude] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
要注意几点:
1. sourceApplication=%@&backScheme=%@
sourceApplication代表你自己APP的名称 会在之后跳回的时候显示出来 所以必须填写 backScheme是你APP的URL Scheme 不填是跳不回来的哟
2. dev=0
这里填0就行了,跟上面的gcj02一个意思 1代表wgs84 也用不上
谷歌:
NSString *urlString = [[NSString stringWithFormat:@
"comgooglemaps://?x-source=%@&x-success=%@&saddr=&daddr=%f,%f&directionsmode=driving"
,appName,urlScheme,coordinate.latitude, coordinate.longitude] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];