ios项目中调用百度、高德、本机地图导航(二)

话不多说直接上代码:

本机地图

第一步 准备工作

导入      两个库


第二步 代码部分

在需要调用的.h文件中加入
#import 
#import 


然后调用代码
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提醒" message:@"启动本机地图" preferredStyle:UIAlertControllerStyleAlert];


UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
UIAlertAction *ok = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
    //百度地图
    [self startiosMap];
    
}];
[alert addAction:cancel];
[alert addAction:ok];

[self presentViewController:alert animated:YES completion:nil];


//本机地图
-(void) startiosMap
{
    CLLocationCoordinate2D myLocation = CLLocationCoordinate2DMake(29.569389,106.557978);
    CLLocationCoordinate2D storeLoacation = CLLocationCoordinate2DMake(29.615133,106.605053);
    
    //高德的坐标转换接口
    myLocation = AMapCoordinateConvert(myLocation, AMapCoordinateTypeGPS);
    storeLoacation =AMapCoordinateConvert(storeLoacation, AMapCoordinateTypeGPS);
    
    MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];
    MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:storeLoacation addressDictionary:nil]];
    toLocation.name = @“美心洋人街”;
    
    [MKMapItem openMapsWithItems:@[currentLocation, toLocation]
                   launchOptions:@{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving,MKLaunchOptionsShowsTrafficKey: [NSNumber numberWithBool:YES]}];
}


 
   
 
  

你可能感兴趣的:(地图开发)