iOS第三方之高德地圖

目錄
  概念
  集成
  1. 地圖顯示與交互
  2. 用戶定位
      單次定位
      持續(xù)定位
      設(shè)備方向監(jiān)測(cè)
      區(qū)域監(jiān)測(cè)
      用戶位置顯示
  3. 大頭針
  4. 覆蓋物
  5. 室內(nèi)地圖
  6. 自定義地圖 樣式
  7. 離線地圖
  8. MAMapViewDelegate

概念

高德地圖分為:
    普通版(常用)
    專業(yè)版(高度自定義:可自定義地圖元素紋理 ) 

用于:
    地圖顯示與交互
    添加覆蓋物、大頭針
    用戶定位(反地理編碼)
    POI檢索
    離線地圖

集成

0.高德開發(fā)者平臺(tái)
    創(chuàng)建應(yīng)用并獲取Key

1.
Plist+
  訪問位置權(quán)限

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

/*
其他

 #pragma mark 高德
 #pragmark 不含IDFA
 #pragma mark 地圖(2D和3D只能選擇一個(gè))
 #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 導(dǎo)航(包含3D地圖)
 pod 'AMapNavi-NO-IDFA'
或
 #pragmark 含IDFA
 pod 'AMap3DMap'
 pod 'AMap2DMap'
 pod 'AMapSearch'
 pod 'AMapLocation' 
 pod 'AMapNavi'
*/

3.AppDelegate
#import <AMapFoundationKit/AMapFoundationKit.h>
[AMapServices sharedServices].apiKey = @"key";

4.見下方使用
1. 地圖顯示與交互
#import <MAMapKit/MAMapKit.h>
#import <AMapFoundationKit/AMapFoundationKit.h>

    // 創(chuàng)建地圖
    MAMapView *mapView = [MAMapView new];
    [mapView setFrame:self.view.bounds];
    [self.view addSubview:mapView];

    // 地圖類型
    [mapView setMapType:MAMapTypeStandard];
    /*
     MAMapTypeStandard = 0,  ///< 普通地圖
     MAMapTypeSatellite,     ///< 衛(wèi)星地圖
     MAMapTypeStandardNight, ///< 夜景視圖
     MAMapTypeNavi,          ///< 導(dǎo)航視圖
     MAMapTypeBus            ///< 公交視圖
     */

交互

縮放
    // 雙擊可放大1倍(捏合縮小,拉伸放大)
    // 縮放級(jí)別(3-19,室內(nèi):3-20)
    [mapView setZoomLevel:14.6];
    [mapView setZoomLevel:14 animated:true];
    [mapView setZoomEnabled:true];
    [mapView setMaxZoomLevel:16];
    [mapView setMinZoomLevel:6];
    // 是否以screenAnchor點(diǎn)作為錨點(diǎn)進(jìn)行縮放,默認(rèn)為true。如果為false,則以手勢(shì)中心點(diǎn)作為錨點(diǎn)
    [mapView setZoomingInPivotsAroundAnchorPoint:true];
    [mapView setZoomLevel:0 atPivot:CGPointMake(0, 0) animated:true];


旋轉(zhuǎn)
    [mapView setRotateEnabled:true];
    [mapView setRotationDegree:180];    // 逆時(shí)針為正向
    [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];


截圖(在指定區(qū)域)
    UIImage *snapImg=[mapView takeSnapshotInRect:CGRectMake(0, 0, 0, 0)];
    [mapView takeSnapshotInRect:CGRectMake(0, 0, 0, 0) withCompletionBlock:^(UIImage *resultImage, NSInteger state) {
        // state:0代表截圖時(shí)地圖載入不完整,1代表地圖載入完整
    }];


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

顯示

地圖顯示范圍
    // 設(shè)置 地圖中心位置
    [mapView setCenterCoordinate:CLLocationCoordinate2DMake(0, 0)];
    [mapView setCenterCoordinate:CLLocationCoordinate2DMake(0, 0) animated:true];
    // 設(shè)置地圖要顯示的范圍(地圖自動(dòng)調(diào)整為相應(yīng)的范圍以顯示該范圍)
    [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];
    // 設(shè)置邊界(只顯示邊界內(nèi))
    [mapView setLimitRegion:MACoordinateRegionMake(CLLocationCoordinate2DMake(0, 0), MACoordinateSpanMake(0, 0))];
    [mapView setLimitMapRect:MAMapRectMake(0, 0, 100, 50)];
    // 根據(jù)frame調(diào)整地圖region范圍(返回調(diào)整后的地圖范圍)
    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)];


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

logo(可通過(guò)地圖位置進(jìn)行隱藏)
    // logo位置(默認(rèn):左下方)
    [mapView setLogoCenter:CGPointMake(0, 0)];
    // logoSize(readOnly)
    CGSize logoSize=[mapView logoSize];


指南針(默認(rèn):右上角)
    // 是否顯示
    [mapView setShowsCompass:true];
    // 圖片
    [mapView setCompassImage:[UIImage imageNamed:@""]];
    // 位置
    [mapView setCompassOrigin:CGPointMake(0, 0)];
    // 指南大?。╮eadOnly)
    CGSize size=[mapView compassSize];


交通路況
    [mapView setShowTraffic:true];
    // 路線顏色
    [mapView setTrafficStatus:@{@(MATrafficStatusSlow):[UIColor redColor]}];
    /*
     MATrafficStatusSmooth = 1,                  ///< 1 通暢
     MATrafficStatusSlow,                        ///< 2 緩行
     MATrafficStatusJam,                         ///< 3 阻塞
     MATrafficStatusSeriousJam,                  ///< 4 嚴(yán)重阻塞
     */
    // 路線寬系數(shù)(0-1)默認(rèn)0.8
    [mapView setTrafficRatio:0.5];

計(jì)算

坐標(biāo)轉(zhuǎn)換
    // 經(jīng)緯度-->指定view坐標(biāo)系的坐標(biāo)
    CGPoint point=[mapView convertCoordinate:CLLocationCoordinate2DMake(0, 0) toPointToView:[UIView new]];
    // 指定view坐標(biāo)系的坐標(biāo)-->經(jīng)緯度
    CLLocationCoordinate2D loc=[mapView convertPoint:CGPointMake(0, 0) toCoordinateFromView:[UIView new]];
    // 經(jīng)緯度region-->指定view坐標(biāo)系的rect
    CGRect rect=[mapView convertRegion:MACoordinateRegionMake(CLLocationCoordinate2DMake(0, 0), MACoordinateSpanMake(0, 0)) toRectToView:[UIView new]];
    // 指定view坐標(biāo)系的rect-->經(jīng)緯度region
    MACoordinateRegion region=[mapView convertRect:CGRectMake(0, 0, 0, 0) toRegionFromView:[UIView new]];

其他

離線
    // 將離線地圖解壓到 Documents/3dvmap/ 目錄下后,調(diào)用此函數(shù)使離線數(shù)據(jù)生效
    // 對(duì)應(yīng)的回調(diào)分別是 offlineDataWillReload:(MAMapView *)mapView, offlineDataDidReload:(MAMapView *)mapView
    [mapView reloadMap];
    // 清除所有磁盤上緩存的地圖數(shù)據(jù)(不包括離線地圖)
    [mapView clearDisk];
    // 重新加載內(nèi)部紋理,在紋理被錯(cuò)誤釋放時(shí)可以執(zhí)行此方法
    [mapView reloadInternalTexture];


審圖號(hào)
    // 獲取地圖審圖號(hào)。如果啟用了“自定義樣式”功能(customMapStyleEnabled 為 YES),則返回nil
    NSString *mapContentApprovalNumber=[mapView mapContentApprovalNumber];
    // 獲取衛(wèi)星圖片審圖號(hào)
    NSString *satelliteImageApprovalNumber=[mapView satelliteImageApprovalNumber];


渲染
    // 最大幀數(shù)(有效的幀數(shù)為:60、30、20、10等能被60整除的數(shù)。默認(rèn)為60)
    NSUInteger maxRenderFrame=[mapView maxRenderFrame];
    // 是否允許降幀
    BOOL isAllowDecreaseFrame=[mapView isAllowDecreaseFrame];
    // 是否開啟OpenGLES繪制
    [mapView setOpenGLESDisabled:true];
    // 地圖渲染的runloop mode(默認(rèn)為NSRunLoopCommonModes)
    [mapView setRunLoopMode:NSRunLoopCommonModes];
   

其他
    // 點(diǎn)擊地圖獲取POI信息
    // 回調(diào)-(void)mapView:(MAMapView *) didTouchPois:(NSArray *){}
    [mapView setTouchPOIEnabled:true];
    // 天空模式
    [mapView setSkyModelEnable:true];
    // 樓塊
    [mapView setShowsBuildings:true];
    // 底圖標(biāo)注(地圖上的顯示文字)
    [mapView setShowsLabels:true];
    // 是否在國(guó)內(nèi)(readOnly)
    BOOL isChina=[mapView isAbroad];
    // 設(shè)置 地圖錨點(diǎn)
    [mapView setScreenAnchor:CGPointMake(0, 0)];
    // 1點(diǎn)對(duì)應(yīng)多少米(readOnly)---當(dāng)前縮放級(jí)別下
    double metersPerPointForCurrentZoom=[mapView metersPerPointForCurrentZoom];
    // 1點(diǎn)對(duì)應(yīng)多少米---指定縮放級(jí)別
    double metersPerPointForZoom=[mapView metersPerPointForZoomLevel:16];
2.用戶定位
plist+權(quán)限

<!-- 位置 --> 
<key>NSLocationUsageDescription</key> 
<string>App需要您的同意,才能訪問位置</string> 
<!-- 在使用期間訪問位置 --> 
<key>NSLocationWhenInUseUsageDescription</key> 
<string>App需要您的同意,才能在使用期間訪問位置</string> 
<!-- 始終訪問位置 --> 
<key>NSLocationAlwaysUsageDescription</key> 
<string>App需要您的同意,才能始終訪問位置</string> 
#import <AMapFoundationKit/AMapFoundationKit.h>
#import <AMapLocationKit/AMapLocationKit.h>

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

單次定位

    // 1. 創(chuàng)建locationManager
    self.locationManager = [AMapLocationManager new];
    /* 
    // 需在單次定位請(qǐng)求前設(shè)置
    // 單次定位超時(shí)時(shí)間(默認(rèn)為10s,最小值是2s)
    [self.locationManager setLocationTimeout:2];
    // 單次定位逆地理超時(shí)時(shí)間(默認(rèn)為5s,最小值是2s)
    [self.locationManager setReGeocodeTimeout:2];

    其他配置 (參考連續(xù)定位)
    */
    // 2.單次定位(是否逆地理(返回坐標(biāo)和地址信息))
    [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;
            // 國(guó)家
            NSString *country=regeocode.country;
            // 省/直轄市
            NSString *province=regeocode.province;
            // 市
            NSString *city=regeocode.city;
            // 區(qū)
            NSString *district=regeocode.district;
            // 城市編碼
            NSString *citycode=regeocode.citycode;
            // 區(qū)域編碼
            NSString *adcode=regeocode.adcode;
            // 街道名稱
            NSString *street=regeocode.street;
            // 門牌號(hào)
            NSString *number=regeocode.number;
            // 興趣點(diǎn)名稱
            NSString *POIName=regeocode.POIName;
            // 所屬興趣點(diǎn)名稱
            NSString *AOIName=regeocode.AOIName;
        }
    }];

連續(xù)定位

    // 1. 創(chuàng)建locationManager
    self.locationManager = [AMapLocationManager new];
    [self.locationManager setDelegate:self];
    // 設(shè)置 最小更新距離(m)(默認(rèn)為kCLDistanceFilterNone,任何移動(dòng)都會(huì)更新)
    [self.locationManager setDistanceFilter:100];
    // 設(shè)置 定位精度
    [self.locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
    /* 精度越高,需時(shí)越長(zhǎng)
     kCLLocationAccuracyBestForNavigation
     kCLLocationAccuracyBest                    10m左右,耗時(shí)10s左右
     kCLLocationAccuracyNearestTenMeters
     kCLLocationAccuracyHundredMeters           100m左右,耗時(shí)2s左右
     kCLLocationAccuracyKilometer
     kCLLocationAccuracyThreeKilometers
     */
    // 是否自動(dòng)停止更新(在不需要的時(shí)候)
    [self.locationManager setPausesLocationUpdatesAutomatically:true];
    // 是否后臺(tái)更新
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9) {
        [self.locationManager setAllowsBackgroundLocationUpdates:true];
    }else{
        // 保持不會(huì)被系統(tǒng)掛起
        [self.locationManager setPausesLocationUpdatesAutomatically:NO];
    }
    // 連續(xù)定位是否返回逆地理信息(默認(rèn)NO)
    [self.locationManager setLocatingWithReGeocode:true];

    // 2.開始持續(xù)定位(如需后臺(tái)定位則 Capabilities | Background Modes 勾選 Location updates)
    [self.locationManager startUpdatingLocation];
    // 停止持續(xù)性定位
    [self.locationManager stopUpdatingLocation];
// 3.定位數(shù)據(jù)更新后回調(diào)(實(shí)現(xiàn)后不再回調(diào)下面的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.定位數(shù)據(jù)更新后回調(diào)
- (void)amapLocationManager:(AMapLocationManager *)manager didUpdateLocation:(CLLocation *)location{
    NSLog(@"location:{lat:%f; lon:%f; accuracy:%f}", location.coordinate.latitude, location.coordinate.longitude, location.horizontalAccuracy);
}
// 定位失敗后回調(diào)
- (void)amapLocationManager:(AMapLocationManager *)manager didFailWithError:(NSError *)error{
    NSLog(@"%@",error);
}
// 定位權(quán)限狀態(tài)改變后回調(diào)
- (void)amapLocationManager:(AMapLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status{
    /*
    kCLAuthorizationStatusNotDetermined         未檢測(cè)
    kCLAuthorizationStatusRestricted
    kCLAuthorizationStatusDenied                拒絕
    kCLAuthorizationStatusAuthorizedAlways      一直
    kCLAuthorizationStatusAuthorizedWhenInUse   使用時(shí)
    kCLAuthorizationStatusAuthorized
     */
}

監(jiān)聽設(shè)備方向

    // 監(jiān)聽設(shè)備朝向
    [self.locationManager startUpdatingHeading];
    // 停止監(jiān)聽設(shè)備方向
    [self.locationManager stopUpdatingHeading];
// 是否顯示設(shè)備朝向
- (BOOL)amapLocationManagerShouldDisplayHeadingCalibration:(AMapLocationManager *)manager{
    return true;
}
// 設(shè)備方向改變后回調(diào)
- (void)amapLocationManager:(AMapLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading{
}

監(jiān)測(cè)區(qū)域

// 圍欄管理者
@property (nonatomic,strong) AMapGeoFenceManager *geoFenceManager;
<AMapGeoFenceManagerDelegate>
// 圍欄管理者
@property (nonatomic,strong) AMapGeoFenceManager *geoFenceManager;
    // 1. 創(chuàng)建圍欄管理者
    self.geoFenceManager = [AMapGeoFenceManager new];
    self.geoFenceManager.delegate = self;   // AMapGeoFenceManagerDelegate
    // 設(shè)置觸發(fā)回調(diào)的條件 進(jìn)入(默認(rèn))| 離開| 停留(在圍欄內(nèi)10分鐘以上)
    self.geoFenceManager.activeAction = AMapGeoFenceActiveActionInside | AMapGeoFenceActiveActionOutside | AMapGeoFenceActiveActionStayed;
    /*
     AMapGeoFenceActiveActionNone     = 0,       ///< 不進(jìn)行監(jiān)聽
     AMapGeoFenceActiveActionInside   = 1 << 0,  ///< 在范圍內(nèi)
     AMapGeoFenceActiveActionOutside  = 1 << 1,  ///< 在范圍外
     AMapGeoFenceActiveActionStayed   = 1 << 2,  ///< 停留(在范圍內(nèi)超過(guò)10分鐘)
     */
    self.geoFenceManager.allowsBackgroundLocationUpdates = YES;  // 允許后臺(tái)定位
    // 是否允許自動(dòng)暫停(不需要時(shí))
    [self.geoFenceManager setPausesLocationUpdatesAutomatically:true];
    

    // 遠(yuǎn)離圍欄時(shí)逐漸降低定位頻率
    
    // 2.1 添加圍欄(根據(jù) POI關(guān)鍵字)
    // size(最大創(chuàng)建的圍欄數(shù)目,最大值為25,默認(rèn)值為10)
    [self.geoFenceManager addKeywordPOIRegionForMonitoringWithKeyword:@"POI關(guān)鍵字" POIType:@"POI類型" city:@"POI所在的城市名稱" size:10 customID:@"cusId"];
    // 2.2 添加圍欄(根據(jù) 周邊POI)
    // Radius(0-50000米,默認(rèn)為3000米,搜索半徑)
    [self.geoFenceManager addAroundPOIRegionForMonitoringWithLocationPoint:CLLocationCoordinate2DMake(116, 39) aroundRadius:1000 keyword:@"POI關(guān)鍵字" POIType:@"POI類型" size:10 customID:@"cusId"];
    // 2.3 添加圍欄(根據(jù) 行政區(qū)關(guān)鍵字)
    [self.geoFenceManager addDistrictRegionForMonitoringWithDistrictName:@"行政區(qū)域關(guān)鍵字" 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:@""];
// 創(chuàng)建圍欄后調(diào)用
- (void)amapGeoFenceManager:(AMapGeoFenceManager *)manager didAddRegionForMonitoringFinished:(NSArray<AMapGeoFenceRegion *> *)regions customID:(NSString *)customID error:(NSError *)error {
    if (error) {
        NSLog(@"創(chuàng)建失敗 %@",error);
    } else {
        NSLog(@"創(chuàng)建成功");
    }
}
// 圍欄狀態(tài)改變后調(diào)用
- (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]);
    }
}
    // 是否國(guó)內(nèi)
    BOOL flag= AMapLocationDataAvailableForCoordinate(CLLocationCoordinate2DMake(39.948691, 116.492479));

用戶位置顯示

注意:
     當(dāng)覆寫了viewForAnnotation會(huì)導(dǎo)致定位圖標(biāo)消失,需要在該方法中+
     if ([annotation isKindOfClass:[MAUserLocation class]]) {
        return nil;
     }
    // 設(shè)置/獲取 是否顯示用戶位置
    @property (nonatomic) BOOL showsUserLocation;



自定義用戶位置顯示樣式
    // 如果設(shè)置了 用戶位置大頭針視圖,則無(wú)效
    // 創(chuàng)建
    MAUserLocationRepresentation *r=[MAUserLocationRepresentation new];
    // 配置
    // 刷新
    [mapView updateUserLocationRepresentation:r];

    MAUserLocationRepresentation: NSObject
    // 是否顯示 精度圈(默認(rèn)true)
    @property (nonatomic, assign) BOOL showsAccuracyRing;
    // 是否顯示 方向指示(默認(rèn)true)
    // MAUserTrackingModeFollowWithHeading模式下開啟
    @property (nonatomic, assign) BOOL showsHeadingIndicator;
    // 精度圈 填充顏色(默認(rèn) kAccuracyCircleDefaultColor)
    @property (nonatomic, strong) UIColor *fillColor;
    // 精度圈 邊線顏色(默認(rèn) kAccuracyCircleDefaultColor)
    @property (nonatomic, strong) UIColor *strokeColor;
    // 精度圈 邊線寬度(默認(rèn)0)
    @property (nonatomic, assign) CGFloat lineWidth;
    
    // 定位點(diǎn) 背景色(默認(rèn)白色)
    @property (nonatomic, strong) UIColor *locationDotBgColor;
    // 定位點(diǎn) 藍(lán)色圓點(diǎn)顏色(默認(rèn)藍(lán)色)
    @property (nonatomic, strong) UIColor *locationDotFillColor;
    // 內(nèi)部藍(lán)色圓點(diǎn)是否使用動(dòng)畫效果(默認(rèn)YES)
    @property (nonatomic, assign) BOOL enablePulseAnnimation;
    // 定位圖標(biāo)(與藍(lán)色原點(diǎn)互斥)
    @property (nonatomic, strong) UIImage* image;
    // 是否自定義用戶位置精度圈(默認(rèn)為 false)(如果為YES,會(huì)調(diào)用:)
    // - (MAOverlayRenderer *)mapView (MAMapView *)mapView rendererForOverlay:(id <MAOverlay>)overlay 返回nil, 則默認(rèn)
    @property (nonatomic) BOOL customizeUserLocationAccuracyCircleRepresentation;
    // 用戶位置精度圈 對(duì)應(yīng)的overlay(readonly)
    MACircle *userLocationAccuracyCircle=mapView.userLocationAccuracyCircle;

定位相關(guān)的

    // 設(shè)置 用戶位置定位的Mode
    [mapView setUserTrackingMode:MAUserTrackingModeFollow animated:true];
      /*
       MAUserTrackingModeNone              = 0,    ///< 不追蹤用戶的location更新
       MAUserTrackingModeFollow            = 1,    ///< 追蹤用戶的location更新
       MAUserTrackingModeFollowWithHeading = 2     ///< 追蹤用戶的location與heading更新

       注意:在follow模式下,設(shè)置地圖中心點(diǎn)、設(shè)置可見區(qū)域、滑動(dòng)手勢(shì)、選擇annotation操作會(huì)取消follow模式,并觸發(fā) - (void)mapView:(MAMapView *)mapView didChangeUserTrackingMode:(MAUserTrackingMode)mode animated:(BOOL)animated;
       */

    // 設(shè)置定位的最小更新距離。(默認(rèn)為kCLDistanceFilterNone,任何移動(dòng)都會(huì)更新)
    @property (nonatomic) CLLocationDistance distanceFilter;
    // 設(shè)置最小更新角度。(默認(rèn)為1度,設(shè)定為kCLHeadingFilterNone會(huì)提示任何角度改變)
    @property (nonatomic) CLLocationDegrees headingFilter;
    // 設(shè)置定位精度。(默認(rèn)為kCLLocationAccuracyBest)
    @property (nonatomic) CLLocationAccuracy desiredAccuracy;
      /*
       kCLLocationAccuracyBestForNavigation
       kCLLocationAccuracyBest
       kCLLocationAccuracyNearestTenMeters
       kCLLocationAccuracyHundredMeters
       kCLLocationAccuracyKilometer
       kCLLocationAccuracyThreeKilometers
       */

    // 定位是否自動(dòng)暫停
    @property (nonatomic) BOOL pausesLocationUpdatesAutomatically;    
    // 是否允許后臺(tái)定位。(默認(rèn)為NO)
    // 設(shè)置為YES的時(shí)候必須保證 Background Modes 中的 Location updates處于選中狀態(tài),否則會(huì)拋出異常
    @property (nonatomic) BOOL allowsBackgroundLocationUpdates;
    // 用戶位置在地圖中是否可見(readOnly)
    BOOL isUserLocationVisible=mapView.isUserLocationVisible;
    // 當(dāng)前的位置數(shù)據(jù)(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];
    // 經(jīng)緯度(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;
    // 獲取當(dāng)前位置時(shí)的時(shí)間(readOnly)
    NSDate *timestamp=loc.timestamp;
    // 樓層(readOnly)
    CLFloor *floor=loc.floor;
    // 樓數(shù)(readOnly)
    NSInteger level=floor.level;
    // 兩個(gè)位置的距離(兩個(gè)位置)
    CLLocationDistance distance=[loc distanceFromLocation:[CLLocation new]];

CLHeading 方向

CLHeading : NSObject
    // 磁極方向(readOnly)double(0.0 - 359.9)0:正北(以設(shè)備頂端)
    CLLocationDirection magneticHeading=heading.magneticHeading;
    // 方向(readOnly)double(0.0 - 359.9)0:正北(以設(shè)備頂端)
    CLLocationDirection trueHeading=heading.trueHeading;
    // 磁航向與實(shí)際地磁航向的最大偏差(readOnly)
    CLLocationDirection headingAccuracy=heading.headingAccuracy;
    // 磁極x坐標(biāo),y坐標(biāo)(double)(readOnly)
    CLHeadingComponentValue x=heading.x;
    CLHeadingComponentValue y=heading.y;
    CLHeadingComponentValue z=heading.z;
    // 獲取方向時(shí)的時(shí)間
    NSDate *timestamp=heading.timestamp;

MACircle 用戶圖標(biāo)

MACircle : MAShape
    // MACircleView的model

    // 設(shè)置中心點(diǎn)和半徑
    [circle setCircleWithCenterCoordinate:CLLocationCoordinate2DMake(0, 0) radius:10];
    // 該圓的外接map rect(readOnly)
    MAMapRect boundingMapRect=circle.boundingMapRect;    
// 創(chuàng)建
    // 方式1:根據(jù)mapRect生成
    MACircle *circleT=[MACircle circleWithMapRect:MAMapRectMake(0, 0, 0, 0)];
    // 方式2:根據(jù)中心點(diǎn)和半徑生成
    MACircle *circleTe=[MACircle circleWithCenterCoordinate:CLLocationCoordinate2DMake(0, 0) radius:10];

    // 設(shè)置中空區(qū)域,用來(lái)創(chuàng)建中間帶空洞的復(fù)雜圖形
    // 注意:傳入的overlay只支持MAPolgon類型和MACircle類型,不支持與此circle邊相交或在circle外部,不支持hollowShapes彼此間相交,和空洞順序有關(guān),不支持嵌套.
    @property (nonatomic, strong) NSArray<id<MAOverlay>> *hollowShapes;
    // 半徑(m) 負(fù)數(shù)則0
    @property (nonatomic, assign) CLLocationDistance radius;
    // 中心點(diǎn)經(jīng)緯度坐標(biāo)(無(wú)效坐標(biāo)按照{(diào)0,0}處理)
    @property (nonatomic, assign) CLLocationCoordinate2D coordinate;

MAShape

MAShape : NSObject <MAAnnotation> 
    // 標(biāo)題
    @property (nonatomic, copy) NSString *title;
    // 副標(biāo)題
    @property (nonatomic, copy) NSString *subtitle;
3. 添加大頭針
    // 添加大頭針
    // 1.創(chuàng)建大頭針
    MAPointAnnotation *pointAnnotation = [[MAPointAnnotation alloc] init];
    // 1.1 經(jīng)緯度
    pointAnnotation.coordinate = CLLocationCoordinate2DMake(39.989631, 116.481018);
    // 1.2 title
    pointAnnotation.title = @"方恒國(guó)際";
    // 1.3 subTitle
    pointAnnotation.subtitle = @"阜通東大街6號(hào)";
    // 2.add
    [mapView addAnnotation:pointAnnotation];

// 3.dele
// 返回大頭針視圖
- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id <MAAnnotation>)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];
        // 是否動(dòng)畫顯示大頭針(即顯示大頭針從天而降,默認(rèn):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:@""]];
        // 是否可以彈出氣泡(默認(rèn)為false)
        [annotationView setCanShowCallout:true];
        // 大頭針是否可以拖動(dòng)(默認(rèn)為false)
        [annotationView setDraggable:true];
        
        
MAAnnotationView
        // 自定義氣泡視圖, 用于替換默認(rèn)氣泡視圖
        // 注意:此彈出框不會(huì)觸發(fā)-(void)mapView: didAnnotationViewCalloutTapped:
        @property (nonatomic, strong) MACustomCalloutView *customCalloutView;
        // 是否允許彈出callout氣泡視圖
        @property (nonatomic) BOOL canShowCallout;
        // 氣泡視圖位置(默認(rèn):大頭針正上方,正則右下)
        @property (nonatomic) CGPoint calloutOffset;
        // 氣泡視圖左側(cè)的view
        @property (nonatomic, strong) UIView *leftCalloutAccessoryView;
        // 氣泡視圖右側(cè)的view
        @property (nonatomic, strong) UIView *rightCalloutAccessoryView;
        
        // 設(shè)置大頭針位置(中心默認(rèn)位于annotation的坐標(biāo)位置(正則右下))
        @property (nonatomic) CGPoint centerOffset;
        // 自定義大頭針圖片image
        @property (nonatomic, strong) UIImage *image;
        // image所在的UIImageView
        @property (nonatomic, strong, readonly) UIImageView *imageView;
        
        // 是否支持拖動(dòng)
        @property (nonatomic, getter=isDraggable) BOOL draggable;
        // 當(dāng)前view的拖動(dòng)狀態(tài)
        @property (nonatomic) MAAnnotationViewDragState dragState;
        // 是否可交互(默認(rèn)為YES)
        @property (nonatomic, getter=isEnabled) BOOL enabled;
        // 是否高亮
        @property (nonatomic, getter=isHighlighted) BOOL highlighted;
        // 是否處于選中狀態(tài)(mapView selectAnnotation 或 手點(diǎn))
        @property (nonatomic, getter=isSelected) BOOL selected;
        
        // z值,大在上(默認(rèn)為0)
        // zIndex屬性只有在viewForAnnotation或者didAddAnnotationViews回調(diào)中設(shè)置有效。
        @property (nonatomic, assign) NSInteger zIndex;
        // 關(guān)聯(lián)的annotation
        @property (nonatomic, strong) id <MAAnnotation> annotation;
    }

    return nil;
}
    // 大頭針列表(不包含userLocation)(readOnly)
    NSArray *annotations=mapView.annotations;
    // 大頭針可見區(qū)域(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]]];
    
    // 獲取指定投影矩形范圍內(nèi)的標(biāo)注
    NSSet *set=[mapView annotationsInMapRect:MAMapRectMake(0, 0, 0, 0)];
    
    // 根據(jù)大頭針獲取大頭針View
    MAAnnotationView *anView=[mapView viewForAnnotation:[MAPointAnnotation new]];
    // 根據(jù)iden獲取大頭針View
    MAAnnotationView *anDeqView=[mapView dequeueReusableAnnotationViewWithIdentifier:@"iden"];
    // 選中大頭針
    [mapView selectAnnotation:[MAPointAnnotation new] animated:true];
    // 反選大頭針
    [mapView deselectAnnotation:[MAPointAnnotation new] animated:true];
    
    // 設(shè)置地圖使其可以顯示數(shù)組中所有的annotation
    // 如果數(shù)組中只有一個(gè)則直接設(shè)置地圖中心為annotation的位置
    [mapView showAnnotations:@[[MAPointAnnotation new]] animated:true];
    [mapView showAnnotations:@[[MAPointAnnotation new]] edgePadding:UIEdgeInsetsMake(0, 0, 0, 0) animated:true];

自定義大頭針: MAPointAnnotation

#import <UIKit/UIKit.h>
#import <MAMapKit/MAMapKit.h>
typedef enum {
    AnnotionTypeGirl,
    AnnotionTypeBoy
}AnnotionType;

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


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

自定義大頭針視圖

CustomAnnotationView : MAAnnotationView

大頭針動(dòng)畫

    // : MAAnimatedAnnotation
    YTAnimatedTAnnotation *ani=[YTAnimatedTAnnotation new];
    // 添加動(dòng)畫
    [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) {
    }];
    
    // 取消所有動(dòng)畫
    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;
    // 創(chuàng)建折線
    MAPolyline *commonPolyline = [MAPolyline polylineWithCoordinates:commonPolylineCoords count:4];
    // 添加覆蓋物
    [mapView addOverlay: commonPolyline];
- (MAOverlayRenderer *)mapView:(MAMapView *)mapView rendererForOverlay:(id <MAOverlay>)overlay{
    
    if ([overlay isKindOfClass:[MAPolyline class]]){
        // 
        MAPolylineRenderer *polylineRenderer = [[MAPolylineRenderer alloc] initWithPolyline:overlay];
        

        /* 設(shè)置紋理(僅支持3D)目前僅支持對(duì)折線設(shè)置紋理
         * 紋理圖片須是正方形,寬高是2的整數(shù)冪
         * 設(shè)置了紋理圖片,設(shè)置線顏色、連接類型和端點(diǎn)類型將無(wú)效
         */
        [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,          ///<圓點(diǎn)樣式
         */
        // 連接點(diǎn)類型
        polylineRenderer.lineJoinType = kMALineJoinRound;
        /*
         kMALineJoinBevel,   ///< 斜面連接點(diǎn)
         kMALineJoinMiter,   ///< 斜接連接點(diǎn)
         kMALineJoinRound    ///< 圓角連接點(diǎn)
         */
        // 端點(diǎn)類型
        polylineRenderer.lineCapType  = kMALineCapRound;
        /*
         kMALineCapButt,     ///< 普通頭
         kMALineCapSquare,   ///< 擴(kuò)展頭
         kMALineCapArrow,    ///< 箭頭
         kMALineCapRound     ///< 圓形頭
         */
        
        return polylineRenderer;
    }
    return nil;
}
  1. 繪制面

    // 創(chuàng)建圓
    MACircle *circle = [MACircle circleWithCenterCoordinate:CLLocationCoordinate2DMake(39.952136, 116.50095) radius:5000];
    // 添加覆蓋物
    [mapView addOverlay:circle];
- (MAOverlayRenderer *)mapView:(MAMapView *)mapView rendererForOverlay:(id <MAOverlay>)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<MAOverlay>)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

    /*
     添加瓦片圖層的前提是使用球面墨卡托投影生成了相應(yīng)的瓦片,并按照生成的格式部署在服務(wù)器上
     
    1.根據(jù)URL模版(即指向相關(guān)圖層圖片的URL)創(chuàng)建MATileOverlay對(duì)象。
    2.設(shè)置MATileOverlay的可見最大/最小Zoom值。
    3.設(shè)定MATileOverlay的可渲染區(qū)域。
    4.將MATileOverlay對(duì)象添加到MAMapView中。
     */
        MATileOverlay *tileOverlay = [[MATileOverlay alloc] initWithURLTemplate:kTileOverlayRemoteServerTemplate];
        /* minimumZ 是tileOverlay的可見最小Zoom值. */
        tileOverlay.minimumZ = kTileOverlayRemoteMinZ;
        /* minimumZ 是tileOverlay的可見最大Zoom值. */
        tileOverlay.maximumZ = kTileOverlayRemoteMaxZ;
        /* boundingMapRect 是用來(lái) 設(shè)定tileOverlay的可渲染區(qū)域. */
        tileOverlay.boundingMapRect = MAMapRectWorld;
- (MAOverlayRenderer *)mapView:(MAMapView *)mapView rendererForOverlay:(id <MAOverlay>)overlay{
    if ([overlay isKindOfClass:[MATileOverlay class]]){
        MATileOverlayRenderer *renderer = [[MATileOverlayRenderer alloc] initWithTileOverlay:overlay];
        return renderer;
    }
    return nil;
}

熱力圖

    // 構(gòu)造熱力圖數(shù)據(jù),從locations.json中讀取經(jīng)緯度
    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;//設(shè)置權(quán)重
            [data addObject:node];
        }
    }
    // 1.構(gòu)造熱力圖圖層對(duì)象
    MAHeatMapTileOverlay  *heatMapTileOverlay = [[MAHeatMapTileOverlay alloc] init];
    heatMapTileOverlay.data = data;
    // 構(gòu)造漸變色對(duì)象
    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 <MAOverlay>)overlay{
    if ([overlay isKindOfClass:[MATileOverlay class]]){
        MATileOverlayRenderer *tileOverlayRenderer = [[MATileOverlayRenderer alloc] initWithTileOverlay:overlay];
        return tileOverlayRenderer;
    }
    return nil;
}
  1. 繪制海量點(diǎn)
    // 讀取出經(jīng)緯度數(shù)組(從file)(格式:lon,lat\nlon,lat)到數(shù)組
    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];
            }
        }
    }
    // 根據(jù)items創(chuàng)建海量點(diǎn)Overlay MultiPointOverlay
    MAMultiPointOverlay *_overlay = [[MAMultiPointOverlay alloc] initWithMultiPointItems:items];
    // 添加覆蓋物
    [mapView addOverlay:_overlay];
// 自定義海量點(diǎn)
- (MAOverlayRenderer *)mapView:(MAMapView *)mapView rendererForOverlay:(id <MAOverlay>)overlay{
    //
    if ([overlay isKindOfClass:[MAMultiPointOverlay class]]){
        //
        MAMultiPointOverlayRenderer * renderer = [[MAMultiPointOverlayRenderer alloc] initWithMultiPointOverlay:overlay];
        
        // 設(shè)置圖片
        renderer.icon = [UIImage imageNamed:@"marker_blue"];
        // 設(shè)置錨點(diǎn)
        renderer.anchor = CGPointMake(0.5, 1.0);
        renderer.delegate = self;   // MAMultiPointOverlayRendererDelegate
        
        return renderer;
    }
    
    return nil;
}

<MAMultiPointOverlayRendererDelegate>
// 點(diǎn)擊海量點(diǎn) 
- (void)multiPointOverlayRenderer:(MAMultiPointOverlayRenderer *)renderer didItemTapped:(MAMultiPointItem *)item{
    NSLog(@"item :%@ <%f, %f>", item, item.coordinate.latitude, item.coordinate.longitude);
}

相關(guān)

    // 獲取所有Overlay(readonly)
    NSArray *overlays=mapView.overlays;
    // 獲取位于level下的所有overlays
    NSArray *overArr=[mapView overlaysInLevel:MAOverlayLevelAboveRoads];
    /*MAOverlayLevel:
     MAOverlayLevelAboveRoads = 0,   ///< 在地圖底圖標(biāo)注和興趣點(diǎn)圖標(biāo)之下繪制overlay
     MAOverlayLevelAboveLabels       ///< 在地圖底圖標(biāo)注和興趣點(diǎn)圖標(biāo)之上繪制overlay
     */
    
    // 添加覆蓋物
    // 需覆寫-mapView:rendererForOverlay:
    // MAGroundOverlay默認(rèn)層級(jí)為MAOverlayLevelAboveRoads,其余overlay類型默認(rèn)層級(jí)為MAOverlayLevelAboveLabels
    [mapView addOverlay:<#(id<MAOverlay>)#>];
    // 默認(rèn)添加層級(jí):MAOverlayLevelAboveLabels
    [mapView addOverlays:@[]];
    [mapView addOverlay:<#(id<MAOverlay>)#> level:MAOverlayLevelAboveRoads];
    [mapView addOverlays:@[] level:MAOverlayLevelAboveRoads];
    
    // 插入覆蓋物
    [mapView insertOverlay:<#(id<MAOverlay>)#> atIndex:0];
    [mapView insertOverlay:<#(id<MAOverlay>)#> aboveOverlay:<#(id<MAOverlay>)#>];
    [mapView insertOverlay:<#(id<MAOverlay>)#> belowOverlay:<#(id<MAOverlay>)#>];
    [mapView insertOverlay:<#(id<MAOverlay>)#> atIndex:0 level:MAOverlayLevelAboveRoads];
    
    // 交換覆蓋物
    [mapView exchangeOverlay:<#(id<MAOverlay>)#> withOverlay:<#(id<MAOverlay>)#>];
    [mapView exchangeOverlayAtIndex:0 withOverlayAtIndex:0];
    [mapView exchangeOverlayAtIndex:0 withOverlayAtIndex:0 atLevel:MAOverlayLevelAboveRoads];
    
    // 移除覆蓋物
    [mapView removeOverlay:<#(id<MAOverlay>)#>];
    [mapView removeOverlays:@[]];

    // 設(shè)置地圖使其可以顯示數(shù)組中所有的overlay
    [mapView showOverlays:@[] animated:true];
    [mapView showOverlays:@[] edgePadding:UIEdgeInsetsMake(0, 0, 0, 0) animated:true];
    // 查找指定overlay對(duì)應(yīng)的Renderer
    MAOverlayRenderer *render=[mapView rendererForOverlay:<#(id<MAOverlay>)#>];
5. 室內(nèi)地圖
  縮放級(jí)別≥17級(jí)時(shí),地圖上可以顯示室內(nèi)地圖。
  縮放級(jí)別≥18級(jí)時(shí),不僅可以看到室內(nèi)地圖效果,還允許操作切換樓層,顯示精細(xì)化室內(nèi)地圖。



    // 是否顯示室內(nèi)地圖(默認(rèn)false)
    @property (nonatomic, getter = isShowsIndoorMap) BOOL showsIndoorMap;
    // 是否顯示室內(nèi)地圖默認(rèn)控件,(默認(rèn)true)
    @property (nonatomic, getter = isShowsIndoorMapControl) BOOL showsIndoorMapControl;
    // 默認(rèn)室內(nèi)地圖控件的最大寬高(readonly)
    CGSize indoorMapControlSize=mapView.indoorMapControlSize;
    
    // 設(shè)置 默認(rèn)室內(nèi)地圖控件位置
    [mapView setIndoorMapControlOrigin:CGPointMake(0, 0)];
    // 設(shè)置 當(dāng)前室內(nèi)地圖樓層數(shù)
    [mapView setCurrentIndoorMapFloorIndex:0];
    // 清空室內(nèi)地圖緩存
    [mapView clearIndoorMapCache];
6. 自定義地圖樣式
高德官網(wǎng)自定義平臺(tái) 創(chuàng)建自定義地圖,并保存發(fā)布下載
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];
    // 是否開啟自定義樣式(默認(rèn)false)
    [self.mapView setCustomMapStyleEnabled:YES];
自定義紋理

1.紋理文件
    將需要使用的紋理圖片以數(shù)字命名 如"1.png"、"2.png"。
    將圖片打包成ZIP文件(不能包含文件夾)
    放到Bundle中

2.樣式文件
 style.json {
    "featureType":"land", # 要素類型
    "elementType":"geometry.fill",#要素屬性
    "stylers":{
      "color":"#ffffff",#自定義顏色
      "textureName":"1"#紋理壓縮文件中圖片名稱
    }
  }

3.
    [mapView setCustomTextureResourcePath:@"path"];
    // 是否開啟自定義樣式(默認(rèn)false)
    [self.mapView setCustomMapStyleEnabled:YES];
7. 離線地圖
  3D地圖SDK 支持離線地圖功能,2D不支持
  有離線地圖數(shù)據(jù)時(shí),會(huì)優(yōu)先加載離線地圖
   MAOfflineItem : NSObject
      包含城市編碼、城市名稱、數(shù)據(jù)狀態(tài)等基本信息
   MAOfflineCity城市    MAOfflineProvince省
   MAOfflineItemCommonCity普通城市/ MAOfflineItemMunicipality直轄市/ MAOfflineItemNationWide全國(guó)概要圖
離線地圖管理類
MAOfflineMap : NSObject

    // 獲取MAOfflineMap單例
    MAOfflineMap *offlineMap=[MAOfflineMap sharedOfflineMap];
    // 省數(shù)組(MAOfflineProvince類型)(readonly)
    NSArray<MAOfflineProvince *> *provinces=offlineMap.provinces;
    // 直轄市數(shù)組(MAOfflineItemMunicipality類型)(readonly)
    NSArray<MAOfflineItemMunicipality *> *municipalities=offlineMap.municipalities;
    // 全國(guó)概要圖(readonly)
    MAOfflineItemNationWide *nationWide=offlineMap.nationWide;
    // 城市數(shù)組(包括普通城市與直轄市)(readonly)
    NSArray<MAOfflineCity *> *cities=offlineMap.cities;
    // 離線數(shù)據(jù)的版本號(hào)(如@"20130715")(readonly)
    NSString *version=offlineMap.version;
    
    // 初始化離線地圖完畢后調(diào)用
    // 如果第一次運(yùn)行且offlinePackage.plist文件不存在,則需要首先執(zhí)行此方法。否則MAOfflineMap中的省、市、版本號(hào)等數(shù)據(jù)都為空
    [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];
    

    // 監(jiān)測(cè)新版本
    // 如果有新版本,會(huì)重建所有的數(shù)據(jù),包括provinces、municipalities、nationWide、cities
    [offlineMap checkNewestVersion:^(BOOL hasNewestVersion) {
    }];
8. MAMapViewDelegate
// 地圖顯示區(qū)域即將改變時(shí)調(diào)用
- (void)mapView:(MAMapView *)mapView regionWillChangeAnimated:(BOOL)animated{
}
// 地圖顯示區(qū)域改變后調(diào)用
- (void)mapViewRegionChanged:(MAMapView *)mapView{
}
// 地圖顯示區(qū)域改變完成后調(diào)用
- (void)mapView:(MAMapView *)mapView regionDidChangeAnimated:(BOOL)animated{
}
// 地圖將要發(fā)生移動(dòng)時(shí)調(diào)用
- (void)mapView:(MAMapView *)mapView mapWillMoveByUser:(BOOL)wasUserAction{
}
// 地圖移動(dòng)結(jié)束后調(diào)用
- (void)mapView:(MAMapView *)mapView mapDidMoveByUser:(BOOL)wasUserAction{
}
// 地圖將要發(fā)生縮放時(shí)調(diào)用
- (void)mapView:(MAMapView *)mapView mapWillZoomByUser:(BOOL)wasUserAction{
}
// 地圖縮放結(jié)束后調(diào)用
- (void)mapView:(MAMapView *)mapView mapDidZoomByUser:(BOOL)wasUserAction{
}
// 地圖加載前調(diào)用
- (void)mapViewWillStartLoadingMap:(MAMapView *)mapView{
}
// 地圖加載結(jié)束調(diào)用
- (void)mapViewDidFinishLoadingMap:(MAMapView *)mapView{
}
// 地圖加載失敗后調(diào)用
- (void)mapViewDidFailLoadingMap:(MAMapView *)mapView withError:(NSError *)error{
}
// 將要定位用戶位置時(shí)調(diào)用
- (void)mapViewWillStartLocatingUser:(MAMapView *)mapView{
}
// 停止定位用戶位置時(shí)調(diào)用
- (void)mapViewDidStopLocatingUser:(MAMapView *)mapView{
}
// 位置或者設(shè)備方向更新后調(diào)用
- (void)mapView:(MAMapView *)mapView didUpdateUserLocation:(MAUserLocation *)userLocation updatingLocation:(BOOL)updatingLocation{
}
// 定位失敗后調(diào)用
- (void)mapView:(MAMapView *)mapView didFailToLocateUserWithError:(NSError *)error{
}
// userTrackingMode改變時(shí)調(diào)用
- (void)mapView:(MAMapView *)mapView didChangeUserTrackingMode:(MAUserTrackingMode)mode animated:(BOOL)animated{
}
// 返回自定義大頭針視圖
- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id <MAAnnotation>)annotation{
    /*
      不要在此回調(diào)中對(duì)annotation進(jìn)行select和deselect操作,此時(shí)annotationView還未添加到mapview
      覆寫后用戶位置圖標(biāo)消失,需要+
        if ([annotation isKindOfClass:[MAUserLocation class]]) {
            return nil;
        }
    */
}
// 添加大頭針視圖后調(diào)用
- (void)mapView:(MAMapView *)mapView didAddAnnotationViews:(NSArray *)views{
}
// 選中大頭針視圖后調(diào)用(已選中則不調(diào)用)
- (void)mapView:(MAMapView *)mapView didSelectAnnotationView:(MAAnnotationView *)view{
}
// 取消選中大頭針視圖后調(diào)用(
- (void)mapView:(MAMapView *)mapView didDeselectAnnotationView:(MAAnnotationView *)view{
}
// 拖動(dòng)大頭針視圖后調(diào)用
- (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被整體點(diǎn)擊時(shí)調(diào)用
- (void)mapView:(MAMapView *)mapView didAnnotationViewCalloutTapped:(MAAnnotationView *)view{
}
// 點(diǎn)擊大頭針視圖后調(diào)用
- (void)mapView:(MAMapView *)mapView didAnnotationViewTapped:(MAAnnotationView *)view{
}
// 返回自定義覆蓋物視圖
- (MAOverlayRenderer *)mapView:(MAMapView *)mapView rendererForOverlay:(id <MAOverlay>)overlay{
}
// 添加新的覆蓋物視圖后調(diào)用
- (void)mapView:(MAMapView *)mapView didAddOverlayRenderers:(NSArray *)overlayRenderers{
}
#if MA_INCLUDE_INDOOR
// 室內(nèi)地圖出現(xiàn)后調(diào)用
- (void)mapView:(MAMapView *)mapView didIndoorMapShowed:(MAIndoorInfo *)indoorInfo{
}
// 改變室內(nèi)地圖樓層后調(diào)用
- (void)mapView:(MAMapView *)mapView didIndoorMapFloorIndexChanged:(MAIndoorInfo *)indoorInfo{
}
// 室內(nèi)地圖消失后調(diào)用
- (void)mapView:(MAMapView *)mapView didIndoorMapHidden:(MAIndoorInfo *)indoorInfo{
}
#endif //end of MA_INCLUDE_INDOOR
// 離線地圖數(shù)據(jù)將要被加載時(shí)調(diào)用(調(diào)用了reloadMap)
- (void)offlineDataWillReload:(MAMapView *)mapView{
}
// 離線地圖數(shù)據(jù)加載完成(調(diào)用了reloadMap)
- (void)offlineDataDidReload:(MAMapView *)mapView{
}
// openGLESDisabled改變時(shí)調(diào)用
- (void)mapView:(MAMapView *)mapView didChangeOpenGLESDisabled:(BOOL)openGLESDisabled{
}
// 當(dāng)touchPOIEnabled == YES時(shí),單擊地圖調(diào)用(獲取POI)
- (void)mapView:(MAMapView *)mapView didTouchPois:(NSArray *)pois{
}
// 單擊地圖時(shí)調(diào)用(返回經(jīng)緯度)
- (void)mapView:(MAMapView *)mapView didSingleTappedAtCoordinate:(CLLocationCoordinate2D)coordinate{
}
// 長(zhǎng)按地圖時(shí)調(diào)用(返回經(jīng)緯度)
- (void)mapView:(MAMapView *)mapView didLongPressedAtCoordinate:(CLLocationCoordinate2D)coordinate{
}
//  地圖初始化完成調(diào)用(在此之后,可以進(jìn)行坐標(biāo)計(jì)算)
- (void)mapInitComplete:(MAMapView *)mapView{
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容