iOS高德地图使用笔记

高德地图笔记
一 准备工作
1.前往高德官网,申请key,http://lbs.amap.com/
2.导入高德SDK,使用cocopods
 platform :ios, '7.0' #手机的系统
  target 'AMap' do
  pod 'AMap3DMap'  #3D地图SDK
  #pod 'AMap2DMap' #2D地图SDK (2D和3D不能同时使⽤用)
  pod 'AMapSearch' #搜索服务SDK
  pod 'AMapLocation'
  end
 
二 地图显示
1.AppDelegate.m中倒入#import
 //配置高德Key
    [AMapServices sharedServices].apiKey = @"2a024f9d7c0478c387208cc1c1ae7986";
2.在ViewController中引入#import

@property (strong,nonatomic) MAMapView * mapView;

 ///初始化地图
    _mapView = [[MAMapView alloc] initWithFrame:self.view.bounds];
    //地图中心位置
    _mapView.centerCoordinate = CLLocationCoordinate2DMake(37.785834, -122.406417);
//    _mapView.zoomLevel  缩放级别(默认3-19,有室内地图时为3-20)
    ///把地图添加至view
    [self.view addSubview:_mapView];

 //地图类型
    //    MAMapTypeStandard = 0,  // 普通地图
    //    MAMapTypeSatellite,     // 卫星地图
    //    MAMapTypeStandardNight, // 夜间视图
    //    MAMapTypeNavi,          // 导航视图
    //    MAMapTypeBus            // 公交视图
    _mapView.mapType = arc4random()%5;

三。定位功能
1.打开定位功能
 _mapView.showsUserLocation = YES;
2.在info.plist中配置
NSLocationWhenInUseUsageDescription   提示信息
3.在MAMapView的回调方法中获取经纬度坐标
  //位置或者设备方向更新后,会调用此函数
-(void)mapView:(MAMapView *)mapView didUpdateUserLocation:(MAUserLocation *)userLocation updatingLocation:(BOOL)updatingLocation{
    _currentLocation = userLocation.location;
     NSLog(@"%@",_currentLocation);
}
//当userTrackingMode改变时,调用此接口
- (void)mapView:(MAMapView *)mapView didChangeUserTrackingMode:(MAUserTrackingMode)mode animated:(BOOL)animated{
    if (mode == MAUserTrackingModeNone) {
        [_locationBtn setImage:[UIImage imageNamed:@"location2"] forState:UIControlStateNormal];
    }else{
        [_locationBtn setImage:[UIImage imageNamed:@"location1"] forState:UIControlStateNormal];
    }
}
4.定位模式,三种模式//改变用户定位模式
-(void)locationAction{
    if (_mapView.userTrackingMode != MAUserTrackingModeFollow) {
         //追踪用户的location更新
        [_mapView setUserTrackingMode:MAUserTrackingModeFollow animated:YES];
    }else{
        //不追踪用户的location更新
       [_mapView setUserTrackingMode:MAUserTrackingModeNone animated:YES];
    }
}

5.逆地理编码(点击当前位置,显示位置信息),调用AMapSearchAPI的逆地理编码请求接口
 //初始化搜索
-(void)initSearch{
    _search = [[AMapSearchAPI alloc]init];
    _search.delegate = self;
}
//逆地理编码查询请求
-(void)reGeoAction{
    if (_currentLocation) {
        //逆地理编码请求
        AMapReGeocodeSearchRequest * request = [[AMapReGeocodeSearchRequest alloc]init];
        request.location = [AMapGeoPoint locationWithLatitude:_currentLocation.coordinate.latitude longitude:_currentLocation.coordinate.longitude];
        [_search AMapReGoecodeSearch:request];
    }
}

#pragma mark - AMapSearchDelegate
//搜索出错时回调
-(void)AMapSearchRequest:(id)request didFailWithError:(NSError *)error{
    NSLog(@"request:%@,error:%@",request,error);
}
//地理编码请求搜索正确时返回
-(void)onReGeocodeSearchDone:(AMapReGeocodeSearchRequest *)request response:(AMapReGeocodeSearchResponse *)response{
    NSLog(@"response:%@",response);
    NSString * title = response.regeocode.addressComponent.city;
    if (title.length == 0) {
        title = response.regeocode.addressComponent.province;
    }
    _mapView.userLocation.title = title;
    _mapView.userLocation.subtitle = response.regeocode.formattedAddress;
}

#pragma mark - MAMapViewDelegate
//地图上的圆点被选中时调用
-(void)mapView:(MAMapView *)mapView didSelectAnnotationView:(MAAnnotationView *)view{
    //选中定位AnnotationView时进行逆地理编码查询
    if ([view.annotation isKindOfClass:[MAUserLocation class]]) {
        [self reGeoAction];
    }
}

6.POI周边搜索

//创建搜索按钮
    UIButton * searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    searchBtn.frame = CGRectMake(CGRectGetMaxX(_locationBtn.frame)+30, self.view.frame.size.height-50, 30, 30);
    [self.view addSubview:searchBtn];
    [searchBtn setImage:[UIImage imageNamed:@"search"] forState:UIControlStateNormal];
    searchBtn.layer.cornerRadius = 10;
    [searchBtn addTarget:self action:@selector(pressSearch) forControlEvents:UIControlEventTouchUpInside];
//初始化数组
-(void)initDataArr{
    _pois = [NSArray array];
    _annotations = [NSMutableArray array];
}
//POI周边搜索
-(void)pressSearch{
    if (_currentLocation == nil || _search == nil) {
        NSLog(@"搜索失败");
        return;
    }
    AMapPOIAroundSearchRequest * request = [[AMapPOIAroundSearchRequest alloc]init];
    request.location = [AMapGeoPoint locationWithLatitude:_currentLocation.coordinate.latitude longitude:_currentLocation.coordinate.longitude];
    request.keywords = @"餐饮";
    [_search AMapPOIAroundSearch:request];
}

#pragma mark - AMapSearchDelegate
//搜索出错时回调
-(void)AMapSearchRequest:(id)request didFailWithError:(NSError *)error{
    NSLog(@"request:%@,error:%@",request,error);
}
//POI周边搜索正确请求回调,将数据传入SearchResultViewController并显示在tableView上,点击cell又将选中的信息返回,并在地图上添加大头针
-(void)onPOISearchDone:(AMapPOISearchBaseRequest *)request response:(AMapPOISearchResponse *)response{
    NSLog(@"request:%@",request);
     NSLog(@"response:%@",response);
    if (response.pois.count > 0) {
        _pois = response.pois;
        //清空标注
        [_mapView removeAnnotations:_annotations];
        [_annotations removeAllObjects];
        
        SearchResultViewController * vc = [[SearchResultViewController alloc]init];
        vc.dataArr = _pois;
        vc.chuanCanBlock = ^(AMapPOI * poi){
            MAPointAnnotation * annotation = [[MAPointAnnotation alloc]init];
            annotation.coordinate = CLLocationCoordinate2DMake(poi.location.latitude, poi.location.longitude);
            annotation.title = poi.name;
            annotation.subtitle = poi.address;
            [_annotations addObject:annotation];
            [_mapView addAnnotation:annotation];
        };
        [self presentViewController:vc animated:YES completion:nil];
    }
}

#pragma mark - MAMapViewDelegate
//大头针被点击时创建MAAnnotationView,显示信息,创建类似于TableViewCell复用
-(MAAnnotationView*)mapView:(MAMapView *)mapView viewForAnnotation:(id)annotation{
    if ([annotation isKindOfClass:[MAPointAnnotation class]]) {
        static NSString * reuseIndetifier = @"annotationReuseIndetifier";
        MAPinAnnotationView * annotationView = (MAPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseIndetifier];
        if (annotationView == nil) {
            annotationView = [[MAPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:reuseIndetifier];
            
        }
        annotationView.canShowCallout = YES;
        return annotationView;
    }
    return nil;
}

SearchResultViewController类
#import "SearchResultViewController.h"
@interface SearchResultViewController ()
@property (strong, nonatomic) UITableView *tableView;
@end
@implementation SearchResultViewController
-(void)viewDidLoad{
    [super viewDidLoad];
    [self createNavgationBar];
   
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height-64)];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    [self.view addSubview:_tableView];
}
-(void)createNavgationBar{
    //创建一个导航栏
    UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 64)];
    //创建一个导航栏集合
    UINavigationItem *navItem = [[UINavigationItem alloc]init];
    //在这个集合Item中添加标题,按钮
    //style:设置按钮的风格,一共有三种选择
    //action:@selector:设置按钮的点击事件
    //创建一个左边按钮
    UIBarButtonItem *leftButton =[[UIBarButtonItem alloc]initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(clickLeftButton)];
    //创建一个右边按钮
    UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"右边" style:UIBarButtonItemStylePlain target:self action:@selector(clickLeftButton)];
    //设置导航栏的内容
    [navItem setTitle:@"餐饮"];
    //把导航栏集合添加到导航栏中,设置动画关闭
    [navBar pushNavigationItem:navItem animated:NO];
    //把左右两个按钮添加到导航栏集合中去
    [navItem setLeftBarButtonItem:leftButton];
    [navItem setRightBarButtonItem:rightButton];
    //将标题栏中的内容全部添加到主视图当中
    [self.view addSubview:navBar];
}
-(void)clickLeftButton{
    [self dismissViewControllerAnimated:YES completion:nil];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _dataArr.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
    }
    AMapPOI * poi = _dataArr[indexPath.row];
    cell.textLabel.text = poi.name;
    cell.detailTextLabel.text = poi.address;
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    AMapPOI * poi = _dataArr[indexPath.row];
     self.chuanCanBlock(poi);
    [self dismissViewControllerAnimated:YES completion:nil];
}

7.自定义MAAnnotationView
属性:
/**
 *  关联的annotation
 */
@property (nonatomic, strong) id annotation;

/**
 *  显示的image
 */
@property (nonatomic, strong) UIImage *image;

/**
 *  默认情况下, annotation view的中心位于annotation的坐标位置,可以设置centerOffset改变view的位置,正的偏移使view朝右下方移动,负的朝左上方,单位是屏幕坐标
 */
@property (nonatomic) CGPoint centerOffset;

/**
 *  默认情况下, 弹出的气泡位于view正中上方,可以设置calloutOffset改变view的位置,正的偏移使view朝右下方移动,负的朝左上方,单位是屏幕坐标
 */
@property (nonatomic) CGPoint calloutOffset;

MAPinAnnotationView:提供类似大头针效果的annotation view

//自定义MAAnnotationView
-(MAAnnotationView*)mapView:(MAMapView *)mapView viewForAnnotation:(id)annotation{
    if ([annotation isKindOfClass:[MAPointAnnotation class]]) {
        static NSString * reuseIndetifier = @"annotationReuseIndetifier";
        MAPinAnnotationView * annotationView = (MAPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseIndetifier];
        if (annotationView == nil) {
            annotationView = [[MAPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:reuseIndetifier];
        }
        //自定义图片
        annotationView.image = [UIImage imageNamed:@"annaotation"];
        //禁用大头针的气泡弹出
        annotationView.canShowCallout = NO;
        //设置中心点偏移,使得标注底部中间点成为经纬度对应点
        annotationView.centerOffset = CGPointMake(0, -18);
        return annotationView;
    }
    return nil;
}

8.自定义callout (气泡)
气泡其实就是一个view,自定义气泡就是自定义一个View,首先自定义annotationView,继承自MAAnnotationView,将自定义的callout作为一个属性,在选中时实现父类的方法

#pragma mark - MAMapViewDelegate
//自定义MAAnnotationView
-(MAAnnotationView*)mapView:(MAMapView *)mapView viewForAnnotation:(id)annotation{
    if ([annotation isKindOfClass:[MAPointAnnotation class]]) {
        static NSString * reuseIndetifier = @"annotationReuseIndetifier";
        CustomAnnotationView * annotationView = (CustomAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseIndetifier];
        if (annotationView == nil) {
            annotationView = [[CustomAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:reuseIndetifier];
        }
        //自定义图片
        annotationView.image = [UIImage imageNamed:@"annaotation"];
        //禁用系统大头针的气泡弹出
        annotationView.canShowCallout = NO;
        //设置中心点偏移,使得标注底部中间点成为经纬度对应点
        annotationView.centerOffset = CGPointMake(0, -18);
        return annotationView;
    }
    return nil;
}
自定义的气泡CustomCalloutView
@interface CustomCalloutView : UIView
@property (strong,nonatomic) NSString * title;
@property (strong,nonatomic) NSString * subTitle;
@property (strong,nonatomic) UIImage * image;
@end
#import "CustomCalloutView.h"
#define kArrorHeight 10
#define kPortraitMargin 5
#define kPortraitWidth 70
#define kPortraitHeight 50
#define kTitleWidth 120
#define kTitleHeight 20

@interface CustomCalloutView ()
@property (strong,nonatomic) UIImageView * portraitView;
@property (strong,nonatomic) UILabel * subtitleLabel;
@property (strong,nonatomic) UILabel * titleLabel;
@end

@implementation CustomCalloutView

-(id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        self.userInteractionEnabled = NO;
        [self initSubViews];
    }
    return self;
}
-(void)initSubViews{
   //添加图片
    self.portraitView = [[UIImageView alloc]initWithFrame:CGRectMake(kPortraitMargin, kPortraitMargin, kPortraitWidth, kPortraitHeight)];
    self.portraitView.backgroundColor = [UIColor blueColor];
    [self addSubview:self.portraitView];
    //添加标题
    self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(kPortraitMargin * 2+kPortraitWidth, kPortraitMargin, kTitleWidth, kTitleHeight)];
    self.titleLabel.font = [UIFont boldSystemFontOfSize:14];
    self.titleLabel.textColor = [UIColor whiteColor];
    self.titleLabel.text = @"title";
    [self addSubview:self.titleLabel];
    //地址
    self.subtitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(kPortraitMargin * 2+kPortraitWidth, kPortraitMargin*2+kTitleHeight, kTitleWidth, kTitleHeight)];
    self.subtitleLabel.font = [UIFont boldSystemFontOfSize:12];
    self.subtitleLabel.textColor = [UIColor lightGrayColor];
    self.subtitleLabel.text = @"subtitleLabel";
    [self addSubview:self.subtitleLabel];
}
-(void)setTitle:(NSString *)title{
    self.titleLabel.text = title;
}
-(void)setSubTitle:(NSString *)subTitle{
    self.subtitleLabel.text = subTitle;
}
-(void)setImage:(UIImage *)image{
    self.portraitView.image = image;
}
#pragma mark - drawRect绘制气泡背景
-(void)drawRect:(CGRect)rect{
    [self drawInContext:UIGraphicsGetCurrentContext()];
    self.layer.shadowColor = [UIColor blackColor].CGColor;
    self.layer.shadowOpacity = 1.0;
    self.layer.shadowOffset = CGSizeMake(0.0f, 0.0f);
}
-(void)drawInContext:(CGContextRef)context{
    CGContextSetLineWidth(context, 2.0);//线宽
    CGContextSetFillColorWithColor(context, [UIColor colorWithRed:0.3 green:0.3 blue:0.3 alpha:0.8].CGColor);//填充颜色
    [self getDrawPath:context];
    CGContextFillPath(context);
}
-(void)getDrawPath:(CGContextRef)context{
#define kArrorHeight 10
    CGRect rrect = self.bounds;
    CGFloat radius = 6.0;
    CGFloat minx = CGRectGetMinX(rrect),
            midx = CGRectGetMidX(rrect),
            maxx = CGRectGetMaxX(rrect);
    CGFloat miny = CGRectGetMinY(rrect),
            maxy = CGRectGetMaxY(rrect) - kArrorHeight;
    
    CGContextMoveToPoint(context, midx+kArrorHeight, maxy);
    CGContextAddLineToPoint(context, midx, maxy+kArrorHeight);
    CGContextAddLineToPoint(context, midx-kArrorHeight, maxy);
    
    CGContextAddArcToPoint(context, minx, maxy, minx, miny, radius);
    CGContextAddArcToPoint(context, minx, miny, maxx, miny, radius);
    CGContextAddArcToPoint(context, maxx, miny, maxx, maxy, radius);
    CGContextAddArcToPoint(context, maxx, maxy, minx, maxy, radius);
    CGContextClosePath(context);
}
@end

自定义的AnnotationView
h文件
#import "CustomCalloutView.h"

@interface CustomAnnotationView : MAAnnotationView
@property (readonly,nonatomic) CustomCalloutView * calloutView;

@end

m文件
#import "CustomAnnotationView.h"

@interface CustomAnnotationView ()
@property (strong,nonatomic,readwrite) CustomCalloutView * calloutView;
@end
@implementation CustomAnnotationView
@synthesize calloutView = _calloutView;

#pragma mark - 重写父类的选种方法
-(void)setSelected:(BOOL)selected animated:(BOOL)animated{
    if (self.selected == selected) {
        return;
    }
    if (selected) {
        if (self.calloutView == nil) {
#define kCalloutWidth   200.0
#define kCalloutHeight   70.0
            
            self.calloutView = [[CustomCalloutView alloc]initWithFrame:CGRectMake(0, 0, kCalloutWidth, kCalloutHeight)];
            self.calloutView.center = CGPointMake(CGRectGetWidth(self.bounds)/2.f+self.calloutOffset.x, -CGRectGetHeight(self.calloutView.bounds)/2.f+self.calloutOffset.y);
        }
        self.calloutView.title = self.annotation.title;
        self.calloutView.subTitle = self.annotation.subtitle;
        NSString * imageName = [NSString stringWithFormat:@"jiudian%d",arc4random()%3+1];
        self.calloutView.image = [UIImage imageNamed:imageName];
        [self addSubview:self.calloutView];
    }else{
        [self.calloutView removeFromSuperview];
    }
    [super setSelected:selected animated:animated];
}

#pragma mark - 重写父类的方法,用以实现点击callotView判断为点击该annotationView
-(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event{
    BOOL inside = [super pointInside:point withEvent:event];
    if (!inside && self.selected) {
        inside = [self.calloutView pointInside:[self convertPoint:point toView:self.calloutView] withEvent:event];
    }
    return inside;
}
@end

8.路线规划
1.长按手势添加目的地
取得手势屏幕坐标,转换为经纬度坐标,获得目的地的经纬度,在MAMapView中有坐标转换接口
//初始化手势
    _recognizer = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(clickLongRecognizer:)];
    _recognizer.delegate = self;
    [_mapView addGestureRecognizer:_recognizer];


2.坐标转换,添加目的地
//长按手势事件
-(void)clickLongRecognizer:(UILongPressGestureRecognizer*)recognizer{
    if (recognizer.state == UIGestureRecognizerStateBegan) {
        //将指定view坐标系的坐标转换为经纬度
        CLLocationCoordinate2D coordinate = [_mapView convertPoint:[recognizer locationInView:_mapView] toCoordinateFromView:_mapView];
        //添加标注
        if (_destinationPoint != nil) {
            //清理
            [_mapView removeAnnotation:_destinationPoint];
            _destinationPoint = nil;
        }
        _destinationPoint = [[MAPointAnnotation alloc]init];
        _destinationPoint.coordinate = coordinate;
        _destinationPoint.title = @"目的地";
        [_mapView addAnnotation:_destinationPoint];
    }
}

3.搜索路线
//路线规划按钮事件
-(void)pressSearchPath{
    if (_currentLocation == nil || _destinationPoint == nil || _search == nil) {
        NSLog(@"路线规划失败");
        return;
    }
    //步行路径规划
    AMapWalkingRouteSearchRequest * request = [[AMapWalkingRouteSearchRequest alloc]init];
    request.multipath = 1;//是否提供备选步行方案: 0-只提供一条步行方案; 1-提供备选步行方案(有可能无备选方案)
    request.origin = [AMapGeoPoint locationWithLatitude:_currentLocation.coordinate.latitude longitude:_currentLocation.coordinate.longitude];//出发点
    request.destination = [AMapGeoPoint locationWithLatitude:_destinationPoint.coordinate.latitude longitude:_destinationPoint.coordinate.longitude];//目的地
    //search请求
    [_search AMapWalkingRouteSearch:request];
}
#pragma mark - AMapSearchDelegate
//路径规划查询回调
-(void)onRouteSearchDone:(AMapRouteSearchBaseRequest *)request response:(AMapRouteSearchResponse *)response{
    if (response.count > 0) {
        [_mapView removeOverlays:_pathPolyLines];
        _pathPolyLines = nil;
    }
    //只显示一条
    _pathPolyLines = [self polylinesForPath:response.route.paths[0]];
    [_mapView addOverlays:_pathPolyLines];//作为覆盖物添加到地图上
    [_mapView showAnnotations:@[_destinationPoint,_mapView.userLocation] animated:YES];
}
- (NSArray *)polylinesForPath:(AMapPath *)path
{
    NSLog(@"%@",path);
    if (path == nil || path.steps.count == 0)
    {
        return nil;//如果path=nil或者导航路段数为零
    }
    NSMutableArray *polylines = [NSMutableArray array];
    [path.steps enumerateObjectsUsingBlock:^(AMapStep *step, NSUInteger idx, BOOL *stop) {
        NSUInteger count = 0;
        CLLocationCoordinate2D *coordinates = [self coordinatesForString:step.polyline coordinateCount:&count parseToken:@";"];
        //根据经纬度坐标数据生成多段线
        MAPolyline *polyline = [MAPolyline polylineWithCoordinates:coordinates count:count];
        [polylines addObject:polyline];
        free(coordinates), coordinates = NULL;
    }];
    return polylines;
}
- (CLLocationCoordinate2D *)coordinatesForString:(NSString *)string coordinateCount:(NSUInteger *)coordinateCount parseToken:(NSString *)token{
    if (string == nil)
    {
        return NULL;
    }
    if (token == nil)
    {
        token = @",";
    }
    NSString *str = @"";
    if (![token isEqualToString:@","])
    {
        str = [string stringByReplacingOccurrencesOfString:token withString:@","];
    }
    else
    {
        str = [NSString stringWithString:string];
    }
    NSArray *components = [str componentsSeparatedByString:@","];
    NSUInteger count = [components count] / 2;
    if (coordinateCount != NULL)
    {
        *coordinateCount = count;
    }
    CLLocationCoordinate2D *coordinates = (CLLocationCoordinate2D*)malloc(count * sizeof(CLLocationCoordinate2D));
    
    for (int i = 0; i < count; i++)
    {
        coordinates[i].longitude = [[components objectAtIndex:2 * i]     doubleValue];
        coordinates[i].latitude  = [[components objectAtIndex:2 * i + 1] doubleValue];
    }
    return coordinates;
}

4.绘制路线
/**
 * @brief 根据overlay生成对应的Renderer
 * @param mapView 地图View
 * @param overlay 指定的overlay
 * @return 生成的覆盖物Renderer
 */
- (MAOverlayRenderer *)mapView:(MAMapView *)mapView rendererForOverlay:(id )overlay{
    if ([overlay isKindOfClass:[MAPolyline class]]) {
        MAPolylineRenderer *polylineRenderer = [[MAPolylineRenderer alloc] initWithPolyline:overlay];
        polylineRenderer.lineWidth   = 8;
        polylineRenderer.lineDash = NO;
        polylineRenderer.strokeColor = [UIColor redColor];
        polylineRenderer.lineJoinType = kMALineJoinRound;
        polylineRenderer.lineCapType = kMALineCapRound;
        return polylineRenderer;
    }
    return nil;
}

你可能感兴趣的:(iOS高德地图使用笔记)