美文网首页iOS常用
iOS 跳转 百度地图 高德地图 自带地图

iOS 跳转 百度地图 高德地图 自带地图

作者: 唐人街的乞丐 | 来源:发表于2020-07-09 17:19 被阅读0次

在做地图跳转操作之前请先在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]}];

相关文章

网友评论

    本文标题:iOS 跳转 百度地图 高德地图 自带地图

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