需求:在百度地图表面和图标的中间,添加一层带透明度的遮罩
1.遵守BMKMapViewDelegate协议
2.实现协议方法
- (BMKOverlayView *)mapView:(BMKMapView *)mapView viewForOverlay:(id <BMKOverlay>)overlay{
if ([overlay isKindOfClass:[BMKCircle class]]){
BMKCircleView* circleView = [[BMKCircleView alloc] initWithOverlay:overlay] ;
circleView.fillColor = [RGB(254, 254, 254) colorWithAlphaComponent:0.3];
circleView.strokeColor = [[UIColor blueColor] colorWithAlphaComponent:1];
circleView.lineWidth = 1;
return circleView;
}
if ([overlay isKindOfClass:[BMKGroundOverlay class]]){
BMKGroundOverlayView *groundView = [[BMKGroundOverlayView alloc] initWithOverlay:overlay];
return groundView;
}
return nil;
}
注意点,方法的执行要看的经纬度在不在可视区域内
3.添加代码
第一种圆形的
CLLocationCoordinate2D coor;
coor.latitude = 23.117055306224895;
coor.longitude = 113.2759952545166;
BMKCircle* circle = [BMKCircle circleWithCenterCoordinate:coor radius:500000];
[self.mapView addOverlay:circle];
第二种:区域的
CLLocationCoordinate2D coords[2] = {0};
coords[0].latitude = 39.815;
coords[0].longitude = 116.404;
coords[1].latitude = 23.117055306224895;
coords[1].longitude = 113.2759952545166;
BMKCoordinateBounds bound;
bound.southWest = coords[0];
bound.northEast = coords[1];
BMKGroundOverlay *ground2 = [BMKGroundOverlay groundOverlayWithBounds: bound
icon:[UIImage imageNamed:@"filColor"]];//背景图片
[self.mapView addOverlay:ground2];