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

最后,第二次写博客。。感觉这东西更为了思考,不单单是为了记录。

   

posted @ 2017-03-23 17:31  强天  阅读(3738)  评论(0编辑  收藏  举报