iOS--高德SDK遇見的問題,自定義線路,開啟導航


1.粗心。。。還是要仔細認真的按着文檔來添加相關的庫,下載最新版本的.boudle文件 sdk等,不然會有各種神奇的錯誤

2.精度圈

    ///定位用戶位置的模式

    @property (nonatomic) MAUserTrackingMode userTrackingMode;

       [_mapView setUserTrackingMode:MAUserTrackingModeFollow];//這個是顯示藍色的精度圈

    customizeUserLocationAccuracyCircleRepresentation =  YES;//自定義精度圈

  - (MAOverlayRenderer *)mapView:(MAMapView *)mapView rendererForOverlay:(id <MAOverlay>)overlay ;//用類似於定義規划線路的方法,自定義精度圈。

 3.線路規划

   (1),自定義線路線方法,這個其實就是在高德的demo里面的方法

 1 - (MAOverlayRenderer *)mapView:(MAMapView *)mapView rendererForOverlay:(id<MAOverlay>)overlay
 2 {
 3     if ([overlay isKindOfClass:[SelectableOverlay class]])
 4     {
 5         SelectableOverlay * selectableOverlay = (SelectableOverlay *)overlay;
 6         id<MAOverlay> actualOverlay = selectableOverlay.overlay;
 7         
 8         MAPolylineRenderer *polylineRenderer = [[MAPolylineRenderer alloc] initWithPolyline:actualOverlay];
 9         polylineRenderer.lineWidth = 8.f;
10         polylineRenderer.lineJoinType = kMALineJoinRound;
11         polylineRenderer.lineCapType = kMALineCapArrow;
12         polylineRenderer.strokeColor = selectableOverlay.isSelected ? selectableOverlay.selectedColor : selectableOverlay.regularColor;
13         return polylineRenderer;
14     }
15     
16     return nil;
17 }
#import <MAMapKit/MAMapKit.h>

@interface SelectableOverlay : NSObject<MAOverlay>

@property (nonatomic, assign) NSInteger routeID;

@property (nonatomic, assign, getter = isSelected) BOOL selected;
@property (nonatomic, strong) UIColor * selectedColor;
@property (nonatomic, strong) UIColor * regularColor;

@property (nonatomic, strong) id<MAOverlay> overlay;

- (id)initWithOverlay:(id<MAOverlay>) overlay;

@end


//

#import "SelectableOverlay.h"

@implementation SelectableOverlay

#pragma mark - MAOverlay Protocol

- (CLLocationCoordinate2D)coordinate
{
    return [self.overlay coordinate];
}

- (MAMapRect)boundingMapRect
{
    return [self.overlay boundingMapRect];
}

#pragma mark - Life Cycle

- (id)initWithOverlay:(id<MAOverlay>)overlay
{
    self = [super init];
    if (self)
    {
        self.overlay       = overlay;
        self.selected      = NO;
        self.selectedColor = [UIColor colorWithRed:0.05 green:0.39 blue:0.9  alpha:0.8];
        self.regularColor  = [UIColor colorWithRed:0.5  green:0.6  blue:0.9  alpha:0.8];
    }
    
    return self;
}

@end

4,導航  AMapNaviDriveView

  

/// 駕車導航管理類

@interface AMapNaviDriveManager : AMapNaviBaseManager// manager類,導航,路徑規划控制類

  [self.driveManager addDataRepresentative:self.driveView];

    [self.driveManager startGPSNavi];

/**

 *  多路徑規划時的所有路徑信息,參考 AMapNaviRoute 類.

 */

@property (nonatomic, readonly, nullable) NSDictionary<NSNumber *, AMapNaviRoute *> *naviRoutes;//路徑規划后所有的路徑

//該類是地圖覆蓋物的基類,所有地圖的覆蓋物需要繼承自此類

@protocol MAOverlay <MAAnnotation>  //文檔里面是這樣介紹的,目前就路線規划的時候,獲取,定義路線有用到,還沒有研究清楚...

  [self.mapView removeOverlays:self.mapView.overlays];//這個方法移除現有的overlays,就是規划展示的路徑overlay 好多地方都有用到

5,一些常用的方法

(1)

/* 根據中心點坐標來搜周邊的POI. */

- (void)searchPoiByCenterCoordinate

{

    AMapPOIAroundSearchRequest *request = [[AMapPOIAroundSearchRequest alloc] init];

    

    request.location            = [AMapGeoPoint locationWithLatitude:selfCoordinate.latitude longitude:selfCoordinate.longitude];

    request.keywords            = @"停車場";

    /* 按照距離排序. */

    request.sortrule            = 0;

    request.requireExtension    = YES;

    

    [self.search AMapPOIAroundSearch:request];

}

 (2),向地圖窗口添加標注

    MAAnnotation,地圖的點

  - (void)addAnnotation:(id <MAAnnotation>)annotation;//就是把annoation 添加到地圖上,也就是大頭針,比如位置,poi搜索的結果等

 

 (3),annotation

  - (void)selectAnnotation:(id <MAAnnotation>)annotation animated:(BOOL)animated;//選中某一個annotation,也就是讓某一個annoation是callout出現,比方默認選中某一個點的時候會用到,

  - (void)removeAnnotations:(NSArray *)annotations;//移除所有annotation

(4),單次逆地理定位

  - (BOOL)requestLocationWithReGeocode:(BOOL)withReGeocode completionBlock:(AMapLocatingCompletionBlock)completionBlock;

  @property (nonatomic, copy) AMapLocatingCompletionBlock completionBlock;

  //返回方法  

   self.completionBlock = ^(CLLocation *location, AMapLocationReGeocode *regeocode, NSError *error){};

  ///逆地理信息

  @interface AMapLocationReGeocode : NSObject<NSCopying,NSCoding>//地理信息在這個類里面

 (5),設置地圖中心點

  - (void)setCenterCoordinate:(CLLocationCoordinate2D)coordinate animated:(BOOL)animated;

 (6),路徑規划方法

/**

 *  帶起點的駕車路徑規划

 *

 *  @param startPoints  起點坐標.起點列表的尾點為實際導航起點,其他坐標點為輔助信息,帶有方向性,可有效避免算路到馬路的另一側.

 *  @param endPoints    終點坐標.終點列表的尾點為實際導航終點,其他坐標點為輔助信息,帶有方向性,可有效避免算路到馬路的另一側.

 *  @param wayPoints    途經點坐標,最多支持16個途經點.

 *  @param strategy     路徑的計算策略

 *  @return 規划路徑是否成功

 */

- (BOOL)calculateDriveRouteWithStartPoints:(NSArray<AMapNaviPoint *> *)startPoints

                                 endPoints:(NSArray<AMapNaviPoint *> *)endPoints

                                 wayPoints:(nullable NSArray<AMapNaviPoint *> *)wayPoints

                           drivingStrategy:(AMapNaviDrivingStrategy)strategy;

   //添加路徑到地圖上

  - (void)addOverlay:(id <MAOverlay>)overlay;

 (7),不要太相信百度上的博客...看清楚時間,對照自己的sdk版本...這次就是有了問題各種百度,各種無用工,其實文檔里面說的就聽清楚的,我的導航      AmapNavi.framework版本是2.3.0.47

最后,第二次寫博客。。感覺這東西更為了思考,不單單是為了記錄。

   


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM