iOS第三方之高德地图

目录
  概念
  集成
  1. 地图显示与交互
  2. 用户定位
      单次定位
      持续定位
      设备方向监测
      区域监测
      用户位置显示
  3. 大头针
  4. 覆盖物
  5. 室内地图
  6. 自定义地图 样式
  7. 离线地图
  8. MAMapViewDelegate

概念

高德地图分为:
    普通版(常用)
    专业版(高度自定义:可自定义地图元素纹理 ) 

用于:
    地图显示与交互
    添加覆盖物、大头针
    用户定位(反地理编码)
    POI检索
    离线地图

集成

0.高德开发者平台
    创建应用并获取Key

1.
Plist+
  访问位置权限

cocoaPods+
 #pragma mark 2D
 pod 'AMap2DMap-NO-IDFA'
 #pragma mark 定位
 pod 'AMapLocation-NO-IDFA'

/*
其他

 #pragma mark 高德
 #pragmark 不含IDFA
 #pragma mark 地图(2D和3D只能选择一个)
 #pragma mark 2D
 pod 'AMap2DMap-NO-IDFA'
 #pragma mark 3D
 pod 'AMap3DMap-NO-IDFA'
 #pragam mark 搜素
 pod 'AMapSearch-NO-IDFA'
 #pragma mark 定位
 pod 'AMapLocation-NO-IDFA'
 #pragma mark 导航(包含3D地图)
 pod 'AMapNavi-NO-IDFA'
或
 #pragmark 含IDFA
 pod 'AMap3DMap'
 pod 'AMap2DMap'
 pod 'AMapSearch'
 pod 'AMapLocation' 
 pod 'AMapNavi'
*/

3.AppDelegate
#import 
[AMapServices sharedServices].apiKey = @"key";

4.见下方使用
1. 地图显示与交互
#import 
#import 

    // 创建地图
    MAMapView *mapView = [MAMapView new];
    [mapView setFrame:self.view.bounds];
    [self.view addSubview:mapView];

    // 地图类型
    [mapView setMapType:MAMapTypeStandard];
    /*
     MAMapTypeStandard = 0,  ///< 普通地图
     MAMapTypeSatellite,     ///< 卫星地图
     MAMapTypeStandardNight, ///< 夜景视图
     MAMapTypeNavi,          ///< 导航视图
     MAMapTypeBus            ///< 公交视图
     */

交互

缩放
    // 双击可放大1倍(捏合缩小,拉伸放大)
    // 缩放级别(3-19,室内:3-20)
    [mapView setZoomLevel:14.6];
    [mapView setZoomLevel:14 animated:true];
    [mapView setZoomEnabled:true];
    [mapView setMaxZoomLevel:16];
    [mapView setMinZoomLevel:6];
    // 是否以screenAnchor点作为锚点进行缩放,默认为true。如果为false,则以手势中心点作为锚点
    [mapView setZoomingInPivotsAroundAnchorPoint:true];
    [mapView setZoomLevel:0 atPivot:CGPointMake(0, 0) animated:true];


旋转
    [mapView setRotateEnabled:true];
    [mapView setRotationDegree:180];    // 逆时针为正向
    [mapView setRotationDegree:180 animated:true duration:0.2];


倾斜
    [mapView setRotateCameraEnabled:true];
    // 倾斜角度0-45
    [mapView setCameraDegree:45];
    [mapView setCameraDegree:0 animated:true duration:0.25];


平移(拖拽)
    [mapView setScrollEnabled:true];


截图(在指定区域)
    UIImage *snapImg=[mapView takeSnapshotInRect:CGRectMake(0, 0, 0, 0)];
    [mapView takeSnapshotInRect:CGRectMake(0, 0, 0, 0) withCompletionBlock:^(UIImage *resultImage, NSInteger state) {
        // state:0代表截图时地图载入不完整,1代表地图载入完整
    }];


    // 可指定中心点后交互
    MAMapStatus *status = [mapView getMapStatus];
    status.screenAnchor = CGPointMake(0.5, 0.76);//地图左上为(0,0)点,右下为(1,1)点。
    [mapView setMapStatus:status animated:NO];

显示

地图显示范围
    // 设置 地图中心位置
    [mapView setCenterCoordinate:CLLocationCoordinate2DMake(0, 0)];
    [mapView setCenterCoordinate:CLLocationCoordinate2DMake(0, 0) animated:true];
    // 设置地图要显示的范围(地图自动调整为相应的范围以显示该范围)
    [mapView setRegion:MACoordinateRegionMake(CLLocationCoordinate2DMake(0, 0), MACoordinateSpanMake(3.0, 3.0))];
    [mapView setRegion:MACoordinateRegionMake(CLLocationCoordinate2DMake(0, 0), MACoordinateSpanMake(3.0, 3.0)) animated:true];
    [mapView setVisibleMapRect:MAMapRectMake(0, 0, 100, 50)];
    [mapView setVisibleMapRect:MAMapRectMake(0, 0, 100, 50) animated:true];
    [mapView setVisibleMapRect:MAMapRectMake(0, 0, 100, 50) edgePadding:UIEdgeInsetsMake(0, 0, 0, 0) animated:true];
    // 设置边界(只显示边界内)
    [mapView setLimitRegion:MACoordinateRegionMake(CLLocationCoordinate2DMake(0, 0), MACoordinateSpanMake(0, 0))];
    [mapView setLimitMapRect:MAMapRectMake(0, 0, 100, 50)];
    // 根据frame调整地图region范围(返回调整后的地图范围)
    MACoordinateRegion region=[mapView regionThatFits:MACoordinateRegionMake(CLLocationCoordinate2DMake(0, 0),MACoordinateSpanMake(0, 0))];
    MAMapRect mapRect=[mapView mapRectThatFits:MAMapRectMake(0, 0, 0, 0)];
    MAMapRect mapRect=[mapView mapRectThatFits:MAMapRectMake(0, 0, 0, 0) edgePadding:UIEdgeInsetsMake(0, 0, 0, 0)];


比例尺(默认:左上角)
    // 最大比例是1:10m,最小比例是1:1000Km
    // 是否显示比例尺
    [mapView setShowsScale:true];
    // 比例尺位置
    [mapView setScaleOrigin:CGPointMake(0, 0)];
    // 比例尺size(readOnly)
    CGSize scaleSize=[mapView scaleSize];
    

logo(可通过地图位置进行隐藏)
    // logo位置(默认:左下方)
    [mapView setLogoCenter:CGPointMake(0, 0)];
    // logoSize(readOnly)
    CGSize logoSize=[mapView logoSize];


指南针(默认:右上角)
    // 是否显示
    [mapView setShowsCompass:true];
    // 图片
    [mapView setCompassImage:[UIImage imageNamed:@""]];
    // 位置
    [mapView setCompassOrigin:CGPointMake(0, 0)];
    // 指南大小(readOnly)
    CGSize size=[mapView compassSize];


交通路况
    [mapView setShowTraffic:true];
    // 路线颜色
    [mapView setTrafficStatus:@{@(MATrafficStatusSlow):[UIColor redColor]}];
    /*
     MATrafficStatusSmooth = 1,                  ///< 1 通畅
     MATrafficStatusSlow,                        ///< 2 缓行
     MATrafficStatusJam,                         ///< 3 阻塞
     MATrafficStatusSeriousJam,                  ///< 4 严重阻塞
     */
    // 路线宽系数(0-1)默认0.8
    [mapView setTrafficRatio:0.5];

计算

坐标转换
    // 经纬度-->指定view坐标系的坐标
    CGPoint point=[mapView convertCoordinate:CLLocationCoordinate2DMake(0, 0) toPointToView:[UIView new]];
    // 指定view坐标系的坐标-->经纬度
    CLLocationCoordinate2D loc=[mapView convertPoint:CGPointMake(0, 0) toCoordinateFromView:[UIView new]];
    // 经纬度region-->指定view坐标系的rect
    CGRect rect=[mapView convertRegion:MACoordinateRegionMake(CLLocationCoordinate2DMake(0, 0), MACoordinateSpanMake(0, 0)) toRectToView:[UIView new]];
    // 指定view坐标系的rect-->经纬度region
    MACoordinateRegion region=[mapView convertRect:CGRectMake(0, 0, 0, 0) toRegionFromView:[UIView new]];

其他

离线
    // 将离线地图解压到 Documents/3dvmap/ 目录下后,调用此函数使离线数据生效
    // 对应的回调分别是 offlineDataWillReload:(MAMapView *)mapView, offlineDataDidReload:(MAMapView *)mapView
    [mapView reloadMap];
    // 清除所有磁盘上缓存的地图数据(不包括离线地图)
    [mapView clearDisk];
    // 重新加载内部纹理,在纹理被错误释放时可以执行此方法
    [mapView reloadInternalTexture];


审图号
    // 获取地图审图号。如果启用了“自定义样式”功能(customMapStyleEnabled 为 YES),则返回nil
    NSString *mapContentApprovalNumber=[mapView mapContentApprovalNumber];
    // 获取卫星图片审图号
    NSString *satelliteImageApprovalNumber=[mapView satelliteImageApprovalNumber];


渲染
    // 最大帧数(有效的帧数为:60、30、20、10等能被60整除的数。默认为60)
    NSUInteger maxRenderFrame=[mapView maxRenderFrame];
    // 是否允许降帧
    BOOL isAllowDecreaseFrame=[mapView isAllowDecreaseFrame];
    // 是否开启OpenGLES绘制
    [mapView setOpenGLESDisabled:true];
    // 地图渲染的runloop mode(默认为NSRunLoopCommonModes)
    [mapView setRunLoopMode:NSRunLoopCommonModes];
   

其他
    // 点击地图获取POI信息
    // 回调-(void)mapView:(MAMapView *) didTouchPois:(NSArray *){}
    [mapView setTouchPOIEnabled:true];
    // 天空模式
    [mapView setSkyModelEnable:true];
    // 楼块
    [mapView setShowsBuildings:true];
    // 底图标注(地图上的显示文字)
    [mapView setShowsLabels:true];
    // 是否在国内(readOnly)
    BOOL isChina=[mapView isAbroad];
    // 设置 地图锚点
    [mapView setScreenAnchor:CGPointMake(0, 0)];
    // 1点对应多少米(readOnly)---当前缩放级别下
    double metersPerPointForCurrentZoom=[mapView metersPerPointForCurrentZoom];
    // 1点对应多少米---指定缩放级别
    double metersPerPointForZoom=[mapView metersPerPointForZoomLevel:16];
2.用户定位
plist+权限

 
NSLocationUsageDescription 
App需要您的同意,才能访问位置 
 
NSLocationWhenInUseUsageDescription 
App需要您的同意,才能在使用期间访问位置 
 
NSLocationAlwaysUsageDescription 
App需要您的同意,才能始终访问位置 
#import 
#import 


// 定位管理者
@property (nonatomic,strong) AMapLocationManager *locationManager;

单次定位

    // 1. 创建locationManager
    self.locationManager = [AMapLocationManager new];
    /* 
    // 需在单次定位请求前设置
    // 单次定位超时时间(默认为10s,最小值是2s)
    [self.locationManager setLocationTimeout:2];
    // 单次定位逆地理超时时间(默认为5s,最小值是2s)
    [self.locationManager setReGeocodeTimeout:2];

    其他配置 (参考连续定位)
    */
    // 2.单次定位(是否逆地理(返回坐标和地址信息))
    [self.locationManager requestLocationWithReGeocode:YES completionBlock:^(CLLocation *location, AMapLocationReGeocode *regeocode, NSError *error) {
        
        if (error){
            NSLog(@"locError:{%ld - %@};", (long)error.code, error.localizedDescription);
            if (error.code == AMapLocationErrorLocateFailed){
                return;
            }
        }
        NSLog(@"location:%@", location);
        
        if (regeocode){  // 反编码信息
            NSLog(@"reGeocode:%@", regeocode);

            AMapLocationReGeocode
            // 格式化地址
            NSString *formattedAddress=regeocode.formattedAddress;
            // 国家
            NSString *country=regeocode.country;
            // 省/直辖市
            NSString *province=regeocode.province;
            // 市
            NSString *city=regeocode.city;
            // 区
            NSString *district=regeocode.district;
            // 城市编码
            NSString *citycode=regeocode.citycode;
            // 区域编码
            NSString *adcode=regeocode.adcode;
            // 街道名称
            NSString *street=regeocode.street;
            // 门牌号
            NSString *number=regeocode.number;
            // 兴趣点名称
            NSString *POIName=regeocode.POIName;
            // 所属兴趣点名称
            NSString *AOIName=regeocode.AOIName;
        }
    }];

连续定位

    // 1. 创建locationManager
    self.locationManager = [AMapLocationManager new];
    [self.locationManager setDelegate:self];
    // 设置 最小更新距离(m)(默认为kCLDistanceFilterNone,任何移动都会更新)
    [self.locationManager setDistanceFilter:100];
    // 设置 定位精度
    [self.locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
    /* 精度越高,需时越长
     kCLLocationAccuracyBestForNavigation
     kCLLocationAccuracyBest                    10m左右,耗时10s左右
     kCLLocationAccuracyNearestTenMeters
     kCLLocationAccuracyHundredMeters           100m左右,耗时2s左右
     kCLLocationAccuracyKilometer
     kCLLocationAccuracyThreeKilometers
     */
    // 是否自动停止更新(在不需要的时候)
    [self.locationManager setPausesLocationUpdatesAutomatically:true];
    // 是否后台更新
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9) {
        [self.locationManager setAllowsBackgroundLocationUpdates:true];
    }else{
        // 保持不会被系统挂起
        [self.locationManager setPausesLocationUpdatesAutomatically:NO];
    }
    // 连续定位是否返回逆地理信息(默认NO)
    [self.locationManager setLocatingWithReGeocode:true];

    // 2.开始持续定位(如需后台定位则 Capabilities | Background Modes 勾选 Location updates)
    [self.locationManager startUpdatingLocation];
    // 停止持续性定位
    [self.locationManager stopUpdatingLocation];
// 3.定位数据更新后回调(实现后不再回调下面的3)反地理编码
- (void)amapLocationManager:(AMapLocationManager *)manager didUpdateLocation:(CLLocation *)location reGeocode:(AMapLocationReGeocode *)reGeocode{
    //
    NSLog(@"location:{lat:%f; lon:%f; accuracy:%f}", location.coordinate.latitude, location.coordinate.longitude, location.horizontalAccuracy);
    if (reGeocode){
        NSLog(@"reGeocode:%@", reGeocode);
    }
}
// 3.定位数据更新后回调
- (void)amapLocationManager:(AMapLocationManager *)manager didUpdateLocation:(CLLocation *)location{
    NSLog(@"location:{lat:%f; lon:%f; accuracy:%f}", location.coordinate.latitude, location.coordinate.longitude, location.horizontalAccuracy);
}
// 定位失败后回调
- (void)amapLocationManager:(AMapLocationManager *)manager didFailWithError:(NSError *)error{
    NSLog(@"%@",error);
}
// 定位权限状态改变后回调
- (void)amapLocationManager:(AMapLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status{
    /*
    kCLAuthorizationStatusNotDetermined         未检测
    kCLAuthorizationStatusRestricted
    kCLAuthorizationStatusDenied                拒绝
    kCLAuthorizationStatusAuthorizedAlways      一直
    kCLAuthorizationStatusAuthorizedWhenInUse   使用时
    kCLAuthorizationStatusAuthorized
     */
}

监听设备方向

    // 监听设备朝向
    [self.locationManager startUpdatingHeading];
    // 停止监听设备方向
    [self.locationManager stopUpdatingHeading];
// 是否显示设备朝向
- (BOOL)amapLocationManagerShouldDisplayHeadingCalibration:(AMapLocationManager *)manager{
    return true;
}
// 设备方向改变后回调
- (void)amapLocationManager:(AMapLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading{
}

监测区域

// 围栏管理者
@property (nonatomic,strong) AMapGeoFenceManager *geoFenceManager;

// 围栏管理者
@property (nonatomic,strong) AMapGeoFenceManager *geoFenceManager;
    // 1. 创建围栏管理者
    self.geoFenceManager = [AMapGeoFenceManager new];
    self.geoFenceManager.delegate = self;   // AMapGeoFenceManagerDelegate
    // 设置触发回调的条件 进入(默认)| 离开| 停留(在围栏内10分钟以上)
    self.geoFenceManager.activeAction = AMapGeoFenceActiveActionInside | AMapGeoFenceActiveActionOutside | AMapGeoFenceActiveActionStayed;
    /*
     AMapGeoFenceActiveActionNone     = 0,       ///< 不进行监听
     AMapGeoFenceActiveActionInside   = 1 << 0,  ///< 在范围内
     AMapGeoFenceActiveActionOutside  = 1 << 1,  ///< 在范围外
     AMapGeoFenceActiveActionStayed   = 1 << 2,  ///< 停留(在范围内超过10分钟)
     */
    self.geoFenceManager.allowsBackgroundLocationUpdates = YES;  // 允许后台定位
    // 是否允许自动暂停(不需要时)
    [self.geoFenceManager setPausesLocationUpdatesAutomatically:true];
    

    // 远离围栏时逐渐降低定位频率
    
    // 2.1 添加围栏(根据 POI关键字)
    // size(最大创建的围栏数目,最大值为25,默认值为10)
    [self.geoFenceManager addKeywordPOIRegionForMonitoringWithKeyword:@"POI关键字" POIType:@"POI类型" city:@"POI所在的城市名称" size:10 customID:@"cusId"];
    // 2.2 添加围栏(根据 周边POI)
    // Radius(0-50000米,默认为3000米,搜索半径)
    [self.geoFenceManager addAroundPOIRegionForMonitoringWithLocationPoint:CLLocationCoordinate2DMake(116, 39) aroundRadius:1000 keyword:@"POI关键字" POIType:@"POI类型" size:10 customID:@"cusId"];
    // 2.3 添加围栏(根据 行政区关键字)
    [self.geoFenceManager addDistrictRegionForMonitoringWithDistrictName:@"行政区域关键字" customID:@"cusId"];
    // 2.4 添加圆形围栏
    [self.geoFenceManager addCircleRegionForMonitoringWithCenter:CLLocationCoordinate2DMake(116, 39) radius:100 customID:@"cusId"];
    // 2.5 添加多边形围栏
    [self.geoFenceManager addPolygonRegionForMonitoringWithCoordinates: count:<#(NSInteger)#> customID:<#(NSString *)#>];
    [self.geoFenceManager addPolygonRegionForMonitoringWithCoordinates:<#(CLLocationCoordinate2D *)#> count:count customID:@"polygon_1"];


    // 删除围栏
    [self.geoFenceManager removeAllGeoFenceRegions];
    // 移除指定围栏
    [self.geoFenceManager removeTheGeoFenceRegion:[AMapGeoFenceRegion new]];
    [self.geoFenceManager removeGeoFenceRegionsWithCustomID:@""];
// 创建围栏后调用
- (void)amapGeoFenceManager:(AMapGeoFenceManager *)manager didAddRegionForMonitoringFinished:(NSArray *)regions customID:(NSString *)customID error:(NSError *)error {
    if (error) {
        NSLog(@"创建失败 %@",error);
    } else {
        NSLog(@"创建成功");
    }
}
// 围栏状态改变后调用
- (void)amapGeoFenceManager:(AMapGeoFenceManager *)manager didGeoFencesStatusChangedForRegion:(AMapGeoFenceRegion *)region customID:(NSString *)customID error:(NSError *)error {
    if (error) {
        NSLog(@"status changed error %@",error);
    }else{
        NSLog(@"status changed success %@",[region description]);
    }
}
    // 是否国内
    BOOL flag= AMapLocationDataAvailableForCoordinate(CLLocationCoordinate2DMake(39.948691, 116.492479));

用户位置显示

注意:
     当覆写了viewForAnnotation会导致定位图标消失,需要在该方法中+
     if ([annotation isKindOfClass:[MAUserLocation class]]) {
        return nil;
     }
    // 设置/获取 是否显示用户位置
    @property (nonatomic) BOOL showsUserLocation;



自定义用户位置显示样式
    // 如果设置了 用户位置大头针视图,则无效
    // 创建
    MAUserLocationRepresentation *r=[MAUserLocationRepresentation new];
    // 配置
    // 刷新
    [mapView updateUserLocationRepresentation:r];

    MAUserLocationRepresentation: NSObject
    // 是否显示 精度圈(默认true)
    @property (nonatomic, assign) BOOL showsAccuracyRing;
    // 是否显示 方向指示(默认true)
    // MAUserTrackingModeFollowWithHeading模式下开启
    @property (nonatomic, assign) BOOL showsHeadingIndicator;
    // 精度圈 填充颜色(默认 kAccuracyCircleDefaultColor)
    @property (nonatomic, strong) UIColor *fillColor;
    // 精度圈 边线颜色(默认 kAccuracyCircleDefaultColor)
    @property (nonatomic, strong) UIColor *strokeColor;
    // 精度圈 边线宽度(默认0)
    @property (nonatomic, assign) CGFloat lineWidth;
    
    // 定位点 背景色(默认白色)
    @property (nonatomic, strong) UIColor *locationDotBgColor;
    // 定位点 蓝色圆点颜色(默认蓝色)
    @property (nonatomic, strong) UIColor *locationDotFillColor;
    // 内部蓝色圆点是否使用动画效果(默认YES)
    @property (nonatomic, assign) BOOL enablePulseAnnimation;
    // 定位图标(与蓝色原点互斥)
    @property (nonatomic, strong) UIImage* image;
    // 是否自定义用户位置精度圈(默认为 false)(如果为YES,会调用:)
    // - (MAOverlayRenderer *)mapView (MAMapView *)mapView rendererForOverlay:(id )overlay 返回nil, 则默认
    @property (nonatomic) BOOL customizeUserLocationAccuracyCircleRepresentation;
    // 用户位置精度圈 对应的overlay(readonly)
    MACircle *userLocationAccuracyCircle=mapView.userLocationAccuracyCircle;

定位相关的

    // 设置 用户位置定位的Mode
    [mapView setUserTrackingMode:MAUserTrackingModeFollow animated:true];
      /*
       MAUserTrackingModeNone              = 0,    ///< 不追踪用户的location更新
       MAUserTrackingModeFollow            = 1,    ///< 追踪用户的location更新
       MAUserTrackingModeFollowWithHeading = 2     ///< 追踪用户的location与heading更新

       注意:在follow模式下,设置地图中心点、设置可见区域、滑动手势、选择annotation操作会取消follow模式,并触发 - (void)mapView:(MAMapView *)mapView didChangeUserTrackingMode:(MAUserTrackingMode)mode animated:(BOOL)animated;
       */

    // 设置定位的最小更新距离。(默认为kCLDistanceFilterNone,任何移动都会更新)
    @property (nonatomic) CLLocationDistance distanceFilter;
    // 设置最小更新角度。(默认为1度,设定为kCLHeadingFilterNone会提示任何角度改变)
    @property (nonatomic) CLLocationDegrees headingFilter;
    // 设置定位精度。(默认为kCLLocationAccuracyBest)
    @property (nonatomic) CLLocationAccuracy desiredAccuracy;
      /*
       kCLLocationAccuracyBestForNavigation
       kCLLocationAccuracyBest
       kCLLocationAccuracyNearestTenMeters
       kCLLocationAccuracyHundredMeters
       kCLLocationAccuracyKilometer
       kCLLocationAccuracyThreeKilometers
       */

    // 定位是否自动暂停
    @property (nonatomic) BOOL pausesLocationUpdatesAutomatically;    
    // 是否允许后台定位。(默认为NO)
    // 设置为YES的时候必须保证 Background Modes 中的 Location updates处于选中状态,否则会抛出异常
    @property (nonatomic) BOOL allowsBackgroundLocationUpdates;
    // 用户位置在地图中是否可见(readOnly)
    BOOL isUserLocationVisible=mapView.isUserLocationVisible;
    // 当前的位置数据(readOnly)
    MAUserLocation *userLocation=mapView.userLocation;
        // 是否正在更新(readOnly)
        BOOL updating=userLocation.updating;
        // 位置location(readOnly)详见下
        CLLocation *location=userLocation.location;
        // 方向heading(readOnly)
        CLHeading *heading=userLocation.heading;

CLLocation 位置

CLLocation: NSObject
    CLLocation *loc=[CLLocation new];
    // 经纬度(readOnly)
    CLLocationCoordinate2D coordinate=loc.coordinate;
    // 海拔(readOnly)double
    CLLocationDistance altitude=loc.altitude;
    // 水平精度(readOnly)double
    CLLocationAccuracy horizontalAccuracy=loc.horizontalAccuracy;
    // 垂直精度(readOnly)double
    CLLocationAccuracy verticalAccuracy=loc.verticalAccuracy;
    // 方向(readOnly)(0.0 - 359.9)0:正北 double
    CLLocationDirection course=loc.course;
    // 速度(readOnly)double m/s
    CLLocationSpeed speed=loc.speed;
    // 获取当前位置时的时间(readOnly)
    NSDate *timestamp=loc.timestamp;
    // 楼层(readOnly)
    CLFloor *floor=loc.floor;
    // 楼数(readOnly)
    NSInteger level=floor.level;
    // 两个位置的距离(两个位置)
    CLLocationDistance distance=[loc distanceFromLocation:[CLLocation new]];

CLHeading 方向

CLHeading : NSObject
    // 磁极方向(readOnly)double(0.0 - 359.9)0:正北(以设备顶端)
    CLLocationDirection magneticHeading=heading.magneticHeading;
    // 方向(readOnly)double(0.0 - 359.9)0:正北(以设备顶端)
    CLLocationDirection trueHeading=heading.trueHeading;
    // 磁航向与实际地磁航向的最大偏差(readOnly)
    CLLocationDirection headingAccuracy=heading.headingAccuracy;
    // 磁极x坐标,y坐标(double)(readOnly)
    CLHeadingComponentValue x=heading.x;
    CLHeadingComponentValue y=heading.y;
    CLHeadingComponentValue z=heading.z;
    // 获取方向时的时间
    NSDate *timestamp=heading.timestamp;

MACircle 用户图标

MACircle : MAShape
    // MACircleView的model

    // 设置中心点和半径
    [circle setCircleWithCenterCoordinate:CLLocationCoordinate2DMake(0, 0) radius:10];
    // 该圆的外接map rect(readOnly)
    MAMapRect boundingMapRect=circle.boundingMapRect;    
// 创建
    // 方式1:根据mapRect生成
    MACircle *circleT=[MACircle circleWithMapRect:MAMapRectMake(0, 0, 0, 0)];
    // 方式2:根据中心点和半径生成
    MACircle *circleTe=[MACircle circleWithCenterCoordinate:CLLocationCoordinate2DMake(0, 0) radius:10];

    // 设置中空区域,用来创建中间带空洞的复杂图形
    // 注意:传入的overlay只支持MAPolgon类型和MACircle类型,不支持与此circle边相交或在circle外部,不支持hollowShapes彼此间相交,和空洞顺序有关,不支持嵌套.
    @property (nonatomic, strong) NSArray> *hollowShapes;
    // 半径(m) 负数则0
    @property (nonatomic, assign) CLLocationDistance radius;
    // 中心点经纬度坐标(无效坐标按照{0,0}处理)
    @property (nonatomic, assign) CLLocationCoordinate2D coordinate;

MAShape

MAShape : NSObject  
    // 标题
    @property (nonatomic, copy) NSString *title;
    // 副标题
    @property (nonatomic, copy) NSString *subtitle;
3. 添加大头针
    // 添加大头针
    // 1.创建大头针
    MAPointAnnotation *pointAnnotation = [[MAPointAnnotation alloc] init];
    // 1.1 经纬度
    pointAnnotation.coordinate = CLLocationCoordinate2DMake(39.989631, 116.481018);
    // 1.2 title
    pointAnnotation.title = @"方恒国际";
    // 1.3 subTitle
    pointAnnotation.subtitle = @"阜通东大街6号";
    // 2.add
    [mapView addAnnotation:pointAnnotation];

// 3.dele
// 返回大头针视图
- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id )annotation{
    
        // MAPinAnnotationView不支持自定义Image
    if ([annotation isKindOfClass:[MAPointAnnotation class]]){
        //
        static NSString *pointReuseIndentifier = @"pointReuseIndentifier";
        
        // MAPinAnnotationView : MAAnnotationView
        MAPinAnnotationView*annotationView = (MAPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:pointReuseIndentifier];
        if (annotationView == nil){
            annotationView = [[MAPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pointReuseIndentifier];
        }
        // 大头针颜色
        [annotationView setPinColor:MAPinAnnotationColorPurple];
        // 是否动画显示大头针(即显示大头针从天而降,默认:false)
        [annotationView setAnimatesDrop:true];
        
        
        return annotationView;
    }else{
        //
        static NSString *reuseIndentifier = @"reuseIndentifier";
        MAAnnotationView *annotationView = (MAAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseIndentifier];
        if (annotationView == nil){
            annotationView = [[MAAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseIndentifier];
        }
        [annotationView setImage:[UIImage imageNamed:@""]];
        // 是否可以弹出气泡(默认为false)
        [annotationView setCanShowCallout:true];
        // 大头针是否可以拖动(默认为false)
        [annotationView setDraggable:true];
        
        
MAAnnotationView
        // 自定义气泡视图, 用于替换默认气泡视图
        // 注意:此弹出框不会触发-(void)mapView: didAnnotationViewCalloutTapped:
        @property (nonatomic, strong) MACustomCalloutView *customCalloutView;
        // 是否允许弹出callout气泡视图
        @property (nonatomic) BOOL canShowCallout;
        // 气泡视图位置(默认:大头针正上方,正则右下)
        @property (nonatomic) CGPoint calloutOffset;
        // 气泡视图左侧的view
        @property (nonatomic, strong) UIView *leftCalloutAccessoryView;
        // 气泡视图右侧的view
        @property (nonatomic, strong) UIView *rightCalloutAccessoryView;
        
        // 设置大头针位置(中心默认位于annotation的坐标位置(正则右下))
        @property (nonatomic) CGPoint centerOffset;
        // 自定义大头针图片image
        @property (nonatomic, strong) UIImage *image;
        // image所在的UIImageView
        @property (nonatomic, strong, readonly) UIImageView *imageView;
        
        // 是否支持拖动
        @property (nonatomic, getter=isDraggable) BOOL draggable;
        // 当前view的拖动状态
        @property (nonatomic) MAAnnotationViewDragState dragState;
        // 是否可交互(默认为YES)
        @property (nonatomic, getter=isEnabled) BOOL enabled;
        // 是否高亮
        @property (nonatomic, getter=isHighlighted) BOOL highlighted;
        // 是否处于选中状态(mapView selectAnnotation 或 手点)
        @property (nonatomic, getter=isSelected) BOOL selected;
        
        // z值,大在上(默认为0)
        // zIndex属性只有在viewForAnnotation或者didAddAnnotationViews回调中设置有效。
        @property (nonatomic, assign) NSInteger zIndex;
        // 关联的annotation
        @property (nonatomic, strong) id  annotation;
    }

    return nil;
}
    // 大头针列表(不包含userLocation)(readOnly)
    NSArray *annotations=mapView.annotations;
    // 大头针可见区域(readOnly)
    CGRect rect=mapView.annotationVisibleRect;
    // 选中的大头针列表
    @property (nonatomic, copy) NSArray *selectedAnnotations;

    // 添加大头针,覆写-mapView:viewForAnnotation:返回大头针视图
    [mapView addAnnotation:[MAPointAnnotation new]];
    [mapView addAnnotations:@[[MAPointAnnotation new]]];
    // 移除大头针
    [mapView removeAnnotation:[MAPointAnnotation new]];
    [mapView removeAnnotations:@[[MAPointAnnotation new]]];
    
    // 获取指定投影矩形范围内的标注
    NSSet *set=[mapView annotationsInMapRect:MAMapRectMake(0, 0, 0, 0)];
    
    // 根据大头针获取大头针View
    MAAnnotationView *anView=[mapView viewForAnnotation:[MAPointAnnotation new]];
    // 根据iden获取大头针View
    MAAnnotationView *anDeqView=[mapView dequeueReusableAnnotationViewWithIdentifier:@"iden"];
    // 选中大头针
    [mapView selectAnnotation:[MAPointAnnotation new] animated:true];
    // 反选大头针
    [mapView deselectAnnotation:[MAPointAnnotation new] animated:true];
    
    // 设置地图使其可以显示数组中所有的annotation
    // 如果数组中只有一个则直接设置地图中心为annotation的位置
    [mapView showAnnotations:@[[MAPointAnnotation new]] animated:true];
    [mapView showAnnotations:@[[MAPointAnnotation new]] edgePadding:UIEdgeInsetsMake(0, 0, 0, 0) animated:true];

自定义大头针: MAPointAnnotation

#import 
#import 
typedef enum {
    AnnotionTypeGirl,
    AnnotionTypeBoy
}AnnotionType;

@interface YTCustomAnnotation : MAPointAnnotation
@property (nonatomic,assign) AnnotionType annotionType;
@end


#import "YTCustomAnnotation.h"
@implementation YTCustomAnnotation
@end

自定义大头针视图

CustomAnnotationView : MAAnnotationView

大头针动画

    // : MAAnimatedAnnotation
    YTAnimatedTAnnotation *ani=[YTAnimatedTAnnotation new];
    // 添加动画
    [ani addMoveAnimationWithKeyCoordinates:coords1 count:sizeof(coords1) / sizeof(coords1[0]) withDuration:0.25 withName:@"" completeCallback:^(BOOL isFinished) {
    }];
    [ani addMoveAnimationWithKeyCoordinates:coords1 count:sizeof(coords1) / sizeof(coords1[0]) withDuration:0.25 withName:@"" completeCallback:^(BOOL isFinished) {
    } stepCallback:^(MAAnnotationMoveAnimation *currentAni) {
    }];
    
    // 取消所有动画
    for (MAAnnotationMoveAnimation *animation in [ani allMoveAnimations]) {
        [animation cancel];
    }
4. 覆盖物
  1. 绘制线
    // data
    CLLocationCoordinate2D commonPolylineCoords[4];
    commonPolylineCoords[0].latitude = 39.832136;
    commonPolylineCoords[0].longitude = 116.34095;
    commonPolylineCoords[1].latitude = 39.832136;
    commonPolylineCoords[1].longitude = 116.42095;
    // 创建折线
    MAPolyline *commonPolyline = [MAPolyline polylineWithCoordinates:commonPolylineCoords count:4];
    // 添加覆盖物
    [mapView addOverlay: commonPolyline];
- (MAOverlayRenderer *)mapView:(MAMapView *)mapView rendererForOverlay:(id )overlay{
    
    if ([overlay isKindOfClass:[MAPolyline class]]){
        // 
        MAPolylineRenderer *polylineRenderer = [[MAPolylineRenderer alloc] initWithPolyline:overlay];
        

        /* 设置纹理(仅支持3D)目前仅支持对折线设置纹理
         * 纹理图片须是正方形,宽高是2的整数幂
         * 设置了纹理图片,设置线颜色、连接类型和端点类型将无效
         */
        [polylineRenderer loadStrokeTextureImage:[UIImage imageNamed:@"arrowTexture"]];

        // 线宽
        polylineRenderer.lineWidth    = 8.f;
        // 边框色
        polylineRenderer.strokeColor  = [UIColor colorWithRed:0 green:1 blue:0 alpha:0.6];
        // 填充色
        [polylineRenderer setFillColor:[UIColor redColor]];
        // 线类型
        [polylineRenderer setLineDashType:MALineDashType];
        /*
         kMALineDashTypeNone = 0,     ///<不画虚线
         kMALineDashTypeSquare,       ///<方块样式
         kMALineDashTypeDot,          ///<圆点样式
         */
        // 连接点类型
        polylineRenderer.lineJoinType = kMALineJoinRound;
        /*
         kMALineJoinBevel,   ///< 斜面连接点
         kMALineJoinMiter,   ///< 斜接连接点
         kMALineJoinRound    ///< 圆角连接点
         */
        // 端点类型
        polylineRenderer.lineCapType  = kMALineCapRound;
        /*
         kMALineCapButt,     ///< 普通头
         kMALineCapSquare,   ///< 扩展头
         kMALineCapArrow,    ///< 箭头
         kMALineCapRound     ///< 圆形头
         */
        
        return polylineRenderer;
    }
    return nil;
}
  1. 绘制面

    // 创建圆
    MACircle *circle = [MACircle circleWithCenterCoordinate:CLLocationCoordinate2DMake(39.952136, 116.50095) radius:5000];
    // 添加覆盖物
    [mapView addOverlay:circle];
- (MAOverlayRenderer *)mapView:(MAMapView *)mapView rendererForOverlay:(id )overlay{
    //
    if ([overlay isKindOfClass:[MACircle class]]){
        // 
        MACircleRenderer *circleRenderer = [[MACircleRenderer alloc] initWithCircle:overlay];
        
        // 配置同线
        circleRenderer.lineWidth    = 5.f;
        circleRenderer.strokeColor  = [UIColor colorWithRed:0.6 green:0.6 blue:0.6 alpha:0.8];
        circleRenderer.fillColor    = [UIColor colorWithRed:1.0 green:0.8 blue:0.0 alpha:0.8];
        
        return circleRenderer;
    }
    return nil;
}

图片

    // 图片覆盖物
    MACoordinateBounds coordinateBounds = MACoordinateBoundsMake(CLLocationCoordinate2DMake(39.939577, 116.388331),CLLocationCoordinate2DMake(39.935029, 116.384377));
    MAGroundOverlay *groundOverlay = [MAGroundOverlay groundOverlayWithBounds:coordinateBounds icon:[UIImage imageNamed:@"imgName"]];
    [mapView addOverlay:groundOverlay];
    // 
    mapView.visibleMapRect = groundOverlay.boundingMapRect;
- (MAOverlayRenderer *)mapView:(MAMapView *)mapView rendererForOverlay:(id)overlay{
    if ([overlay isKindOfClass:[MAGroundOverlay class]]){
        //
        MAGroundOverlayRenderer *groundOverlayRenderer = [[MAGroundOverlayRenderer alloc] initWithGroundOverlay:overlay];
        
        return groundOverlayRenderer;
    }
    return nil;
}

瓦片

#define kTileOverlayRemoteServerTemplate @"http://cache1.arcgisonline.cn/arcgis/rest/services/ChinaCities_Community_BaseMap_ENG/BeiJing_Community_BaseMap_ENG/MapServer/tile/{z}/{y}/{x}"
#define kTileOverlayRemoteMinZ      4
#define kTileOverlayRemoteMaxZ      17
#define kTileOverlayLocalMinZ       11
#define kTileOverlayLocalMaxZ       13

    /*
     添加瓦片图层的前提是使用球面墨卡托投影生成了相应的瓦片,并按照生成的格式部署在服务器上
     
    1.根据URL模版(即指向相关图层图片的URL)创建MATileOverlay对象。
    2.设置MATileOverlay的可见最大/最小Zoom值。
    3.设定MATileOverlay的可渲染区域。
    4.将MATileOverlay对象添加到MAMapView中。
     */
        MATileOverlay *tileOverlay = [[MATileOverlay alloc] initWithURLTemplate:kTileOverlayRemoteServerTemplate];
        /* minimumZ 是tileOverlay的可见最小Zoom值. */
        tileOverlay.minimumZ = kTileOverlayRemoteMinZ;
        /* minimumZ 是tileOverlay的可见最大Zoom值. */
        tileOverlay.maximumZ = kTileOverlayRemoteMaxZ;
        /* boundingMapRect 是用来 设定tileOverlay的可渲染区域. */
        tileOverlay.boundingMapRect = MAMapRectWorld;
- (MAOverlayRenderer *)mapView:(MAMapView *)mapView rendererForOverlay:(id )overlay{
    if ([overlay isKindOfClass:[MATileOverlay class]]){
        MATileOverlayRenderer *renderer = [[MATileOverlayRenderer alloc] initWithTileOverlay:overlay];
        return renderer;
    }
    return nil;
}

热力图

    // 构造热力图数据,从locations.json中读取经纬度
    NSMutableArray* data = [NSMutableArray array];
    NSData *jsdata = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"locations" ofType:@"json"]];
    if (jsdata){
        //
        NSArray *dicArray = [NSJSONSerialization JSONObjectWithData:jsdata options:NSJSONReadingAllowFragments error:nil];
        
        for (NSDictionary *dic in dicArray){
            MAHeatMapNode *node = [[MAHeatMapNode alloc] init];
            CLLocationCoordinate2D coordinate;
            coordinate.latitude = [dic[@"lat"] doubleValue];
            coordinate.longitude = [dic[@"lng"] doubleValue];
            node.coordinate = coordinate;
            
            node.intensity = 1;//设置权重
            [data addObject:node];
        }
    }
    // 1.构造热力图图层对象
    MAHeatMapTileOverlay  *heatMapTileOverlay = [[MAHeatMapTileOverlay alloc] init];
    heatMapTileOverlay.data = data;
    // 构造渐变色对象
    MAHeatMapGradient *gradient = [[MAHeatMapGradient alloc] initWithColor:@[[UIColor blueColor],[UIColor greenColor], [UIColor redColor]] andWithStartPoints:@[@(0.2),@(0.5),@(0.9)]];
    heatMapTileOverlay.gradient = gradient;
    
    // 2.将热力图添加到地图上
    [mapView addOverlay: heatMapTileOverlay];
- (MAOverlayRenderer *)mapView:(MAMapView *)mapView rendererForOverlay:(id )overlay{
    if ([overlay isKindOfClass:[MATileOverlay class]]){
        MATileOverlayRenderer *tileOverlayRenderer = [[MATileOverlayRenderer alloc] initWithTileOverlay:overlay];
        return tileOverlayRenderer;
    }
    return nil;
}
  1. 绘制海量点
    // 读取出经纬度数组(从file)(格式:lon,lat\nlon,lat)到数组
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"location" ofType:@"txt"];
    NSString *locationString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
    NSArray *locations = [locationString componentsSeparatedByString:@"\n"];
    NSMutableArray *items = [NSMutableArray array];
    for (int i = 0; i < locations.count; ++i){
        @autoreleasepool {
            MAMultiPointItem *item = [[MAMultiPointItem alloc] init];
            NSArray *coordinate = [locations[i] componentsSeparatedByString:@","];
            
            if (coordinate.count == 2){
                item.coordinate = CLLocationCoordinate2DMake([coordinate[1] floatValue], [coordinate[0] floatValue]);
                [items addObject:item];
            }
        }
    }
    // 根据items创建海量点Overlay MultiPointOverlay
    MAMultiPointOverlay *_overlay = [[MAMultiPointOverlay alloc] initWithMultiPointItems:items];
    // 添加覆盖物
    [mapView addOverlay:_overlay];
// 自定义海量点
- (MAOverlayRenderer *)mapView:(MAMapView *)mapView rendererForOverlay:(id )overlay{
    //
    if ([overlay isKindOfClass:[MAMultiPointOverlay class]]){
        //
        MAMultiPointOverlayRenderer * renderer = [[MAMultiPointOverlayRenderer alloc] initWithMultiPointOverlay:overlay];
        
        // 设置图片
        renderer.icon = [UIImage imageNamed:@"marker_blue"];
        // 设置锚点
        renderer.anchor = CGPointMake(0.5, 1.0);
        renderer.delegate = self;   // MAMultiPointOverlayRendererDelegate
        
        return renderer;
    }
    
    return nil;
}


// 点击海量点 
- (void)multiPointOverlayRenderer:(MAMultiPointOverlayRenderer *)renderer didItemTapped:(MAMultiPointItem *)item{
    NSLog(@"item :%@ <%f, %f>", item, item.coordinate.latitude, item.coordinate.longitude);
}

相关

    // 获取所有Overlay(readonly)
    NSArray *overlays=mapView.overlays;
    // 获取位于level下的所有overlays
    NSArray *overArr=[mapView overlaysInLevel:MAOverlayLevelAboveRoads];
    /*MAOverlayLevel:
     MAOverlayLevelAboveRoads = 0,   ///< 在地图底图标注和兴趣点图标之下绘制overlay
     MAOverlayLevelAboveLabels       ///< 在地图底图标注和兴趣点图标之上绘制overlay
     */
    
    // 添加覆盖物
    // 需覆写-mapView:rendererForOverlay:
    // MAGroundOverlay默认层级为MAOverlayLevelAboveRoads,其余overlay类型默认层级为MAOverlayLevelAboveLabels
    [mapView addOverlay:<#(id)#>];
    // 默认添加层级:MAOverlayLevelAboveLabels
    [mapView addOverlays:@[]];
    [mapView addOverlay:<#(id)#> level:MAOverlayLevelAboveRoads];
    [mapView addOverlays:@[] level:MAOverlayLevelAboveRoads];
    
    // 插入覆盖物
    [mapView insertOverlay:<#(id)#> atIndex:0];
    [mapView insertOverlay:<#(id)#> aboveOverlay:<#(id)#>];
    [mapView insertOverlay:<#(id)#> belowOverlay:<#(id)#>];
    [mapView insertOverlay:<#(id)#> atIndex:0 level:MAOverlayLevelAboveRoads];
    
    // 交换覆盖物
    [mapView exchangeOverlay:<#(id)#> withOverlay:<#(id)#>];
    [mapView exchangeOverlayAtIndex:0 withOverlayAtIndex:0];
    [mapView exchangeOverlayAtIndex:0 withOverlayAtIndex:0 atLevel:MAOverlayLevelAboveRoads];
    
    // 移除覆盖物
    [mapView removeOverlay:<#(id)#>];
    [mapView removeOverlays:@[]];

    // 设置地图使其可以显示数组中所有的overlay
    [mapView showOverlays:@[] animated:true];
    [mapView showOverlays:@[] edgePadding:UIEdgeInsetsMake(0, 0, 0, 0) animated:true];
    // 查找指定overlay对应的Renderer
    MAOverlayRenderer *render=[mapView rendererForOverlay:<#(id)#>];
5. 室内地图
  缩放级别≥17级时,地图上可以显示室内地图。
  缩放级别≥18级时,不仅可以看到室内地图效果,还允许操作切换楼层,显示精细化室内地图。



    // 是否显示室内地图(默认false)
    @property (nonatomic, getter = isShowsIndoorMap) BOOL showsIndoorMap;
    // 是否显示室内地图默认控件,(默认true)
    @property (nonatomic, getter = isShowsIndoorMapControl) BOOL showsIndoorMapControl;
    // 默认室内地图控件的最大宽高(readonly)
    CGSize indoorMapControlSize=mapView.indoorMapControlSize;
    
    // 设置 默认室内地图控件位置
    [mapView setIndoorMapControlOrigin:CGPointMake(0, 0)];
    // 设置 当前室内地图楼层数
    [mapView setCurrentIndoorMapFloorIndex:0];
    // 清空室内地图缓存
    [mapView clearIndoorMapCache];
6. 自定义地图样式
高德官网自定义平台 创建自定义地图,并保存发布下载
http://lbs.amap.com/dev/mapstyle/index
    // 
    NSString *path = [NSString stringWithFormat:@"%@/webExportedStyleData.data", [NSBundle mainBundle].bundlePath];
    NSData *data = [NSData dataWithContentsOfFile:path];
    [self.mapView setCustomMapStyleWithWebData:data];
    // 是否开启自定义样式(默认false)
    [self.mapView setCustomMapStyleEnabled:YES];
自定义纹理

1.纹理文件
    将需要使用的纹理图片以数字命名 如"1.png"、"2.png"。
    将图片打包成ZIP文件(不能包含文件夹)
    放到Bundle中

2.样式文件
 style.json {
    "featureType":"land", # 要素类型
    "elementType":"geometry.fill",#要素属性
    "stylers":{
      "color":"#ffffff",#自定义颜色
      "textureName":"1"#纹理压缩文件中图片名称
    }
  }

3.
    [mapView setCustomTextureResourcePath:@"path"];
    // 是否开启自定义样式(默认false)
    [self.mapView setCustomMapStyleEnabled:YES];
7. 离线地图
  3D地图SDK 支持离线地图功能,2D不支持
  有离线地图数据时,会优先加载离线地图
   MAOfflineItem : NSObject
      包含城市编码、城市名称、数据状态等基本信息
   MAOfflineCity城市    MAOfflineProvince省
   MAOfflineItemCommonCity普通城市/ MAOfflineItemMunicipality直辖市/ MAOfflineItemNationWide全国概要图
离线地图管理类
MAOfflineMap : NSObject

    // 获取MAOfflineMap单例
    MAOfflineMap *offlineMap=[MAOfflineMap sharedOfflineMap];
    // 省数组(MAOfflineProvince类型)(readonly)
    NSArray *provinces=offlineMap.provinces;
    // 直辖市数组(MAOfflineItemMunicipality类型)(readonly)
    NSArray *municipalities=offlineMap.municipalities;
    // 全国概要图(readonly)
    MAOfflineItemNationWide *nationWide=offlineMap.nationWide;
    // 城市数组(包括普通城市与直辖市)(readonly)
    NSArray *cities=offlineMap.cities;
    // 离线数据的版本号(如@"20130715")(readonly)
    NSString *version=offlineMap.version;
    
    // 初始化离线地图完毕后调用
    // 如果第一次运行且offlinePackage.plist文件不存在,则需要首先执行此方法。否则MAOfflineMap中的省、市、版本号等数据都为空
    [offlineMap setupWithCompletionBlock:^(BOOL setupSuccess) {
    }];

    // 下载
    [offlineMap downloadItem:[MAOfflineItemCommonCity new] shouldContinueWhenAppEntersBackground:YES downloadBlock:^(MAOfflineMapDownloadStatus downloadStatus, id info) {
        // 注意主线程刷新UI
    }];
    // 暂停下载
    BOOL isPauseSuccess=[offlineMap pauseItem:[MAOfflineItemCommonCity new]];
    // 是否正在下载
    BOOL isDownloading=[offlineMap isDownloadingForItem:[MAOfflineItemCommonCity new]];
    
    // 删除下载
    [offlineMap deleteItem:[MAOfflineItemCommonCity new]];
    // 取消所有下载
    [offlineMap cancelAll];

    // 清除已下载
    [offlineMap clearDisk];
    

    // 监测新版本
    // 如果有新版本,会重建所有的数据,包括provinces、municipalities、nationWide、cities
    [offlineMap checkNewestVersion:^(BOOL hasNewestVersion) {
    }];
8. MAMapViewDelegate
// 地图显示区域即将改变时调用
- (void)mapView:(MAMapView *)mapView regionWillChangeAnimated:(BOOL)animated{
}
// 地图显示区域改变后调用
- (void)mapViewRegionChanged:(MAMapView *)mapView{
}
// 地图显示区域改变完成后调用
- (void)mapView:(MAMapView *)mapView regionDidChangeAnimated:(BOOL)animated{
}
// 地图将要发生移动时调用
- (void)mapView:(MAMapView *)mapView mapWillMoveByUser:(BOOL)wasUserAction{
}
// 地图移动结束后调用
- (void)mapView:(MAMapView *)mapView mapDidMoveByUser:(BOOL)wasUserAction{
}
// 地图将要发生缩放时调用
- (void)mapView:(MAMapView *)mapView mapWillZoomByUser:(BOOL)wasUserAction{
}
// 地图缩放结束后调用
- (void)mapView:(MAMapView *)mapView mapDidZoomByUser:(BOOL)wasUserAction{
}
// 地图加载前调用
- (void)mapViewWillStartLoadingMap:(MAMapView *)mapView{
}
// 地图加载结束调用
- (void)mapViewDidFinishLoadingMap:(MAMapView *)mapView{
}
// 地图加载失败后调用
- (void)mapViewDidFailLoadingMap:(MAMapView *)mapView withError:(NSError *)error{
}
// 将要定位用户位置时调用
- (void)mapViewWillStartLocatingUser:(MAMapView *)mapView{
}
// 停止定位用户位置时调用
- (void)mapViewDidStopLocatingUser:(MAMapView *)mapView{
}
// 位置或者设备方向更新后调用
- (void)mapView:(MAMapView *)mapView didUpdateUserLocation:(MAUserLocation *)userLocation updatingLocation:(BOOL)updatingLocation{
}
// 定位失败后调用
- (void)mapView:(MAMapView *)mapView didFailToLocateUserWithError:(NSError *)error{
}
// userTrackingMode改变时调用
- (void)mapView:(MAMapView *)mapView didChangeUserTrackingMode:(MAUserTrackingMode)mode animated:(BOOL)animated{
}
// 返回自定义大头针视图
- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id )annotation{
    /*
      不要在此回调中对annotation进行select和deselect操作,此时annotationView还未添加到mapview
      覆写后用户位置图标消失,需要+
        if ([annotation isKindOfClass:[MAUserLocation class]]) {
            return nil;
        }
    */
}
// 添加大头针视图后调用
- (void)mapView:(MAMapView *)mapView didAddAnnotationViews:(NSArray *)views{
}
// 选中大头针视图后调用(已选中则不调用)
- (void)mapView:(MAMapView *)mapView didSelectAnnotationView:(MAAnnotationView *)view{
}
// 取消选中大头针视图后调用(
- (void)mapView:(MAMapView *)mapView didDeselectAnnotationView:(MAAnnotationView *)view{
}
// 拖动大头针视图后调用
- (void)mapView:(MAMapView *)mapView annotationView:(MAAnnotationView *)view didChangeDragState:(MAAnnotationViewDragState)newState
   fromOldState:(MAAnnotationViewDragState)oldState{
}
// 大头针视图的accessView被电击
- (void)mapView:(MAMapView *)mapView annotationView:(MAAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{
}
// 大头针视图德calloutview被整体点击时调用
- (void)mapView:(MAMapView *)mapView didAnnotationViewCalloutTapped:(MAAnnotationView *)view{
}
// 点击大头针视图后调用
- (void)mapView:(MAMapView *)mapView didAnnotationViewTapped:(MAAnnotationView *)view{
}
// 返回自定义覆盖物视图
- (MAOverlayRenderer *)mapView:(MAMapView *)mapView rendererForOverlay:(id )overlay{
}
// 添加新的覆盖物视图后调用
- (void)mapView:(MAMapView *)mapView didAddOverlayRenderers:(NSArray *)overlayRenderers{
}
#if MA_INCLUDE_INDOOR
// 室内地图出现后调用
- (void)mapView:(MAMapView *)mapView didIndoorMapShowed:(MAIndoorInfo *)indoorInfo{
}
// 改变室内地图楼层后调用
- (void)mapView:(MAMapView *)mapView didIndoorMapFloorIndexChanged:(MAIndoorInfo *)indoorInfo{
}
// 室内地图消失后调用
- (void)mapView:(MAMapView *)mapView didIndoorMapHidden:(MAIndoorInfo *)indoorInfo{
}
#endif //end of MA_INCLUDE_INDOOR
// 离线地图数据将要被加载时调用(调用了reloadMap)
- (void)offlineDataWillReload:(MAMapView *)mapView{
}
// 离线地图数据加载完成(调用了reloadMap)
- (void)offlineDataDidReload:(MAMapView *)mapView{
}
// openGLESDisabled改变时调用
- (void)mapView:(MAMapView *)mapView didChangeOpenGLESDisabled:(BOOL)openGLESDisabled{
}
// 当touchPOIEnabled == YES时,单击地图调用(获取POI)
- (void)mapView:(MAMapView *)mapView didTouchPois:(NSArray *)pois{
}
// 单击地图时调用(返回经纬度)
- (void)mapView:(MAMapView *)mapView didSingleTappedAtCoordinate:(CLLocationCoordinate2D)coordinate{
}
// 长按地图时调用(返回经纬度)
- (void)mapView:(MAMapView *)mapView didLongPressedAtCoordinate:(CLLocationCoordinate2D)coordinate{
}
//  地图初始化完成调用(在此之后,可以进行坐标计算)
- (void)mapInitComplete:(MAMapView *)mapView{
}

你可能感兴趣的:(iOS第三方之高德地图)