在做地图跳转操作之前请先在plist文件添加相应的配置参数
App跳转百度地图应用
百度地图文档
路线规划 2.2.3 路线规划
http://lbsyun.baidu.com/index.php?title=uri/api/ios
百度地图调起效果如下:
代码
更多参数请参考官方文档
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake([latStr doubleValue], [lonStr doubleValue]);
CLLocationCoordinate2D baidu_coordinate=[self getBaiDuCoordinateByGaoDeCoordinate:coordinate];
latStr = [NSString stringWithFormat:@"%f",baidu_coordinate.latitude];
lonStr = [NSString stringWithFormat:@"%f",baidu_coordinate.longitude];
NSString *urlString = [[NSString stringWithFormat:@"baidumap://map/direction?origin={{我的位置}}&destination=latlng:%@,%@|name=目的地&mode=driving&coord_type=gcj02",latStr, lonStr] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{UIApplicationOpenURLOptionsSourceApplicationKey:@YES} completionHandler:^(BOOL success) {
}];
+(CLLocationCoordinate2D)getBaiDuCoordinateByGaoDeCoordinate:(CLLocationCoordinate2D)coordinate
{
return CLLocationCoordinate2DMake(coordinate.latitude + 0.006, coordinate.longitude + 0.0065);
}
App跳转高德地图应用
高德地图文档
https://lbs.amap.com/api/amap-mobile/guide/ios/route
高德地图调起效果如下:
代码
更多参数请参考官方文档
NSString *urlString = [[NSString stringWithFormat:@"iosamap://path?sourceApplication=applicationName&did=&dlat=%@&dlon=%@&dname=%@&dev=0&t=0",latStr,lonStr,nameStr] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{UIApplicationOpenURLOptionsSourceApplicationKey:@YES} completionHandler:^(BOOL success) {
}];
App跳转自带地图应用
自带地图调起效果如下:
代码
MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake([latStr doubleValue], [lonStr doubleValue]);
MKMapItem *tolocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:nil]];
tolocation.name=nameStr;
[MKMapItem openMapsWithItems:@[currentLocation,tolocation]launchOptions:@{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving,MKLaunchOptionsShowsTrafficKey:[NSNumber numberWithBool:YES]}];