2.1 高德地图加点划线

高德地图功能丰富,看下添加兴趣点,连接两点画线操作,基本实现api协议,不怎么费力就可以做出常用的功能。

/// pod基础框架和地图包:

  pod 'AMapFoundation', '~> 1.6.2' 

  pod'AMap3DMap', '~> 7.2.0'   

/// 导入要用到的库

#import

#import

/// 遵循协议

MAMapViewDelegate

/// 去官网注册个key绑定bundleid

[AMapServices sharedServices].apiKey = @"xxx";

/// 生成实例对象

@property (nonatomic, strong)MAMapView *mapView;

/// 接下来,添加两个兴趣点poi,一般继承使用,添加标志位,用来区分多个兴趣点

[self.mapView addAnnotation:anno];

[self.mapView addAnnotation:anno1];

/// 基于两个兴趣点画条线

MAMapPointmap_point[2];

        map_point[0] =MAMapPointForCoordinate(anno->coordinate);

        map_point[1] =MAMapPointForCoordinate(anno1->coordinate);

        MAPolyline*line = [MAPolylinepolylineWithPoints:map_pointcount:2];

        [self.mapViewaddOverlay:line];

        NSMutableArray *arrOverlay = [NSMutableArray arrayWithObjects:line, nil];

/// 展示两个兴趣点和连线

        [self.mapView showOverlays:arrOverlay edgePadding:UIEdgeInsetsMake(50, 50, 50, 50) animated:YES];

/// 实现协议,展示兴趣点

- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id)annotation {

/// 用户poi ,拎出来展示

    if([annotationisKindOfClass:[MAUserLocation class]]) {

        MAAnnotationView*userView = [[MAAnnotationViewalloc]initWithAnnotation:annotationreuseIdentifier:@"xxxx"];

        userView.image= [UIImageimageNamed:@"xxx.png"];

        userView.zIndex=1;

        userView.canShowCallout=NO;

        userView.backgroundColor= [UIColorclearColor];

        returnuserView;

    }

/// 根据标志位,做不同的处理

if((xxx*)annotation.flag ==  someType) {

return xxx;

} else if ((xxx*)annotation.flag == anotherType) {

return yyy;

}

}

/// 展示连线

- (MAOverlayRenderer *)mapView:(MAMapView *)mapView rendererForOverlay:(id)overlay {

/// 

    if([overlayisKindOfClass:[MAPolyline class]]) {

        MAPolylineRenderer*lineView = [[MAPolylineRendereralloc]initWithOverlay:overlay];

        lineView.strokeColor    = xxx;

        lineView.strokeColor    = xxx;

        lineView.lineDashType  =kMALineDashTypeDot;

        //lineView.lineDashPattern = [NSArray arrayWithObjects:[NSNumber numberWithInt:10] , [NSNumber numberWithInt:10], nil];

        lineView.lineWidth=4.5;

        returnlineView;

    }

    return nil;

}

你可能感兴趣的:(2.1 高德地图加点划线)