IOS百度地图自定义大头针和气泡

2023-11-08 20:10

本文主要是介绍IOS百度地图自定义大头针和气泡,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

一、自定义大头针和气泡

// 根据anntation生成对应的View
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation
{NSString *AnnotationViewID = [NSString stringWithFormat:@"renameMark%d",i];newAnnotation = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID];// 设置颜色((BMKPinAnnotationView*)newAnnotation).pinColor = BMKPinAnnotationColorPurple;// 从天上掉下效果((BMKPinAnnotationView*)newAnnotation).animatesDrop = YES;// 设置可拖拽((BMKPinAnnotationView*)newAnnotation).draggable = YES;//设置大头针图标((BMKPinAnnotationView*)newAnnotation).image = [UIImage imageNamed:@"zhaohuoche"];UIView *popView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 60)];//设置弹出气泡图片UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"wenzi"]];image.frame = CGRectMake(0, 0, 100, 60);[popView addSubview:image];//自定义显示的内容UILabel *driverName = [[UILabel alloc]initWithFrame:CGRectMake(0, 3, 100, 20)];driverName.text = @"张XX师傅";driverName.backgroundColor = [UIColor clearColor];driverName.font = [UIFont systemFontOfSize:14];driverName.textColor = [UIColor whiteColor];driverName.textAlignment = NSTextAlignmentCenter;[popView addSubview:driverName];UILabel *carName = [[UILabel alloc]initWithFrame:CGRectMake(0, 25, 100, 20)];carName.text = @"京A123456";carName.backgroundColor = [UIColor clearColor];carName.font = [UIFont systemFontOfSize:14];carName.textColor = [UIColor whiteColor];carName.textAlignment = NSTextAlignmentCenter;[popView addSubview:carName];BMKActionPaopaoView *pView = [[BMKActionPaopaoView alloc]initWithCustomView:popView];pView.frame = CGRectMake(0, 0, 100, 60);((BMKPinAnnotationView*)newAnnotation).paopaoView = nil;((BMKPinAnnotationView*)newAnnotation).paopaoView = pView;i++;return newAnnotation;}

二、气泡自定义内容


 最简单,最直接的方法。。。

自定义一个 UIView

核心代码如下:

//改变标注图片和自定义气泡

-(BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id<BMKAnnotation>)annotation

{

    BMKAnnotationView *annotationView=[[BMKAnnotationViewalloc]initWithAnnotation:annotationreuseIdentifier:@"myAnnotation"];

    annotationView.image =[UIImageimageNamed:@"bike.gif"];

    

    //自定义内容气泡

   UIView *areaPaoView=[[UIViewalloc]initWithFrame:CGRectMake(0, 0, 200, 100)];

    areaPaoView.layer.cornerRadius=8;

    areaPaoView.layer.masksToBounds=YES;

    areaPaoView.layer.contents =(id)[UIImageimageNamed:@"pao.png"].CGImage;//这张图片是做好的透明

    //areaPaoView.backgroundColor=[UIColor whiteColor];

        if ([annotation.titleisEqualToString:@"1"]) { //假设title的标题为1,那么就把添加上这个自定义气泡内容

                       UILabel * labelNo = [[UILabelalloc]initWithFrame:CGRectMake(10, 0, 200, 30)];

            labelNo.text =[NSStringstringWithFormat:@"站点编号:%@"];

            labelNo.textColor = [UIColorblackColor];

            labelNo.backgroundColor = [UIColorclearColor];

            [areaPaoViewaddSubview:labelNo];

            

           UILabel * labelStationName = [[UILabelalloc]initWithFrame:CGRectMake(10, 20, 200, 30)];

            labelStationName.text = [NSStringstringWithFormat:@"站点名称:昆山中学"];

            labelStationName.textColor = [UIColorblackColor];

            labelStationName.backgroundColor = [UIColorclearColor];

            [areaPaoViewaddSubview:labelStationName];

            

           UILabel * labelSumNum = [[UILabelalloc]initWithFrame:CGRectMake(10, 40, 200, 30)];

            labelSumNum.text = [NSStringstringWithFormat:@"总桩数:30"];

            labelSumNum.textColor = [UIColorblackColor];

            labelSumNum.backgroundColor = [UIColorclearColor];

            [areaPaoViewaddSubview:labelSumNum];

            

           UILabel * labelBicycleNum = [[UILabelalloc]initWithFrame:CGRectMake(10, 60, 200, 30)];

            labelBicycleNum.text = [NSStringstringWithFormat:@"可借车:20"];

            labelBicycleNum.textColor = [UIColorblackColor];

            labelBicycleNum.backgroundColor = [UIColorclearColor];

            [areaPaoViewaddSubview:labelBicycleNum];


    }    

    BMKActionPaopaoView *paopao=[[BMKActionPaopaoViewalloc]initWithCustomView:areaPaoView];

    annotationView.paopaoView=paopao;

    

    

   return annotationView;

}



三、添加标注自定义气泡

文/煜寒了(简书作者)
原文链接:http://www.jianshu.com/p/6a334f071c69
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。

1.首先实现添加多个标注和自定义气泡

添加自定义标注

[_mapView addAnnotations:array];

arry 中放入标注(BMKPointAnnotation)的数组,此方法添加多个标注。

当添加多个标注时就触发以下代理方法

#pragma mark -- BMKMapdelegate/***根据anntation生成对应的View*@param mapView 地图View*@param annotation 指定的标注*@return 生成的标注View*/
-(BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation
{if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {BMKPinAnnotationView *newAnnotationView = [[BMKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"myAnnotation"];newAnnotationView.animatesDrop = YES;newAnnotationView.annotation = annotation;//这里我根据自己需要,继承了BMKPointAnnotation,添加了标注的类型等需要的信息MyBMKPointAnnotation *tt = (MyBMKPointAnnotation *)annotation;//判断类别,需要添加不同类别,来赋予不同的标注图片if (tt.profNumber == 100000) {newAnnotationView.image = [UIImage imageNamed:@"ic_map_mode_category_merchants_normal.png"];}else if (tt.profNumber == 100001){}//设定popView的高度,根据是否含有缩略图double popViewH = 60;if (annotation.subtitle == nil) {popViewH = 38;}UIView *popView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth-100, popViewH)];popView.backgroundColor = [UIColor whiteColor];[popView.layer setMasksToBounds:YES];[popView.layer setCornerRadius:3.0];popView.alpha = 0.9;
//        //设置弹出气泡图片
//        UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:tt.imgPath]];
//        image.frame = CGRectMake(0, 160, 50, 60);
//        [popView addSubview:image];//自定义气泡的内容,添加子控件在popView上UILabel *driverName = [[UILabel alloc]initWithFrame:CGRectMake(8, 4, 160, 30)];driverName.text = annotation.title;driverName.numberOfLines = 0;driverName.backgroundColor = [UIColor clearColor];driverName.font = [UIFont systemFontOfSize:15];driverName.textColor = [UIColor blackColor];driverName.textAlignment = NSTextAlignmentLeft;[popView addSubview:driverName];UILabel *carName = [[UILabel alloc]initWithFrame:CGRectMake(8, 30, 180, 30)];carName.text = annotation.subtitle;carName.backgroundColor = [UIColor clearColor];carName.font = [UIFont systemFontOfSize:11];carName.textColor = [UIColor lightGrayColor];carName.textAlignment = NSTextAlignmentLeft;[popView addSubview:carName];if (annotation.subtitle != nil) {UIButton *searchBn = [[UIButton alloc]initWithFrame:CGRectMake(170, 0, 50, 60)];[searchBn setTitle:@"查看路线" forState:UIControlStateNormal];searchBn.backgroundColor = mainColor;searchBn.titleLabel.numberOfLines = 0;[searchBn addTarget:self action:@selector(searchLine)];[popView addSubview:searchBn];}BMKActionPaopaoView *pView = [[BMKActionPaopaoView alloc]initWithCustomView:popView];pView.frame = CGRectMake(0, 0, ScreenWidth-100, popViewH);((BMKPinAnnotationView*)newAnnotationView).paopaoView = nil;((BMKPinAnnotationView*)newAnnotationView).paopaoView = pView;return newAnnotationView;}return nil;
}

点击标注和气泡响应方法

/*** 当选中一个annotation views时,调用此接口* @param mapView 地图View* @param views 选中的annotation views*/
- (void)mapView:(BMKMapView *)mapView didSelectAnnotationView:(BMKAnnotationView *)view
{_shopCoor = view.annotation.coordinate;
}
/***  选中气泡调用方法*  @param mapView 地图*  @param view    annotation*/
- (void)mapView:(BMKMapView *)mapView annotationViewForBubble:(BMKAnnotationView *)view
{MyBMKPointAnnotation *tt = (MyBMKPointAnnotation *)view.annotation;if (tt.shopID) {BusinessIfonUVC *BusinessIfonVC = [[BusinessIfonUVC alloc]init];BusinessIfonVC.shopId = tt.shopID;[self.navigationController pushViewController:BusinessIfonVC animated:YES];}
}

2.实现路线搜索,路径规划,获取街道名称等功能

通过经纬度获取地址,逆地理编码

-(void)getStartAddress
{//起点地址CLGeocoder *Geocoder = [[CLGeocoder alloc]init];CLGeocodeCompletionHandler handler = ^(NSArray *place,NSError *error){for(CLPlacemark *placemark in place){NSString *tmp = [[NSString alloc]init];tmp = placemark.subThoroughfare;if (tmp == nil) {tmp = @"";}NSString *startAdr = [[NSString alloc]initWithFormat:@"%@%@",placemark.thoroughfare,tmp];_startCityText.text = placemark.locality;if ([startAdr isEqualToString:@"(null)"]) {_startAddrText.text = @"获取地址失败";}else{_startAddrText.text = startAdr;}}};CLLocation *loc = [[CLLocation alloc]initWithLatitude:self.startCoor.latitude longitude:self.startCoor.longitude];[Geocoder reverseGeocodeLocation:loc completionHandler:handler];}

路径检索,该部分没有整理,将乘车和换乘信息放到了LineInfo,steps等模型中。

- (void)onGetTransitRouteResult:(BMKRouteSearch*)searcher result:(BMKTransitRouteResult*)result errorCode:(BMKSearchErrorCode)error
{NSMutableArray *lineArr = [[NSMutableArray alloc]init];NSArray* array = [NSArray arrayWithArray:_mapView.annotations];[_mapView removeAnnotations:array];array = [NSArray arrayWithArray:_mapView.overlays];[_mapView removeOverlays:array];if (error == BMK_SEARCH_NO_ERROR) {for(int j = 0; j < [result.routes count];j++){NSMutableArray *busTitleArr = [[NSMutableArray alloc]init];NSMutableArray *lineStepsArr = [[NSMutableArray alloc]init];NSMutableArray *stepsArr = [[NSMutableArray alloc]init];//生成数据模型LineInfoModel *lineInfo = [[LineInfoModel alloc]init];BMKTransitRouteLine* plan = (BMKTransitRouteLine*)[result.routes objectAtIndex:j];//数据模型:获得路线长度lineInfo.distance = plan.distance;//数据模型:获得路线消耗时间lineInfo.dates = plan.duration.dates;lineInfo.hours = plan.duration.hours;lineInfo.minutes = plan.duration.minutes;lineInfo.seconds = plan.duration.seconds;// 获得轨迹点lineInfo.planStepsArr = plan.steps;// 计算路线方案中的路段数目int size = [plan.steps count];int planPointCounts = 0;for (int i = 0; i < size; i++) {BMKTransitStep* transitStep = [plan.steps objectAtIndex:i];//数据模型:获得乘坐公交数组DLog(@"%@",transitStep.vehicleInfo.title);if (transitStep.vehicleInfo.title) {[busTitleArr addObject:transitStep.vehicleInfo.title];}//数据模型:获取换乘信息if (transitStep.instruction) {transitStep.instruction = [transitStep.instruction stringByReplacingOccurrencesOfString:@"<font color=\"#313233\">" withString:@""];[lineStepsArr addObject:transitStep.instruction];}DLog(@"%@ %@",transitStep.vehicleInfo.title,transitStep.instruction);if(i==0){RouteAnnotation* item = [[RouteAnnotation alloc]init];item.coordinate = plan.starting.location;item.title = @"起点";item.type = 0;
//                [_mapView addAnnotation:item]; // 添加起点标注
//     
//[stepsArr addObject:item];}else if(i==size-1){RouteAnnotation* item = [[RouteAnnotation alloc]init];item.coordinate = plan.terminal.location;item.title = @"终点";item.type = 1;[stepsArr addObject:item];
//                [_mapView addAnnotation:item]; // 添加起点标注
//          }RouteAnnotation* item = [[RouteAnnotation alloc]init];item.coordinate = transitStep.entrace.location;item.title = transitStep.instruction;transitStep.instruction = [transitStep.instruction stringByReplacingOccurrencesOfString:@"<font color=\"#313233\">" withString:@""];item.type = 3;[stepsArr addObject:item];
//            [_mapView addAnnotation:item];
// 
//            
//            //轨迹点总数累计planPointCounts += transitStep.pointsCount;}lineInfo.vehicleInfoArr = busTitleArr;lineInfo.lineStepsArr = lineStepsArr;lineInfo.stepsArr = stepsArr;lineInfo.planPointCounts = planPointCounts;[lineArr addObject:lineInfo];//        //轨迹点
//        BMKMapPoint * temppoints = new BMKMapPoint[planPointCounts];
//        int i = 0;
//        for (int j = 0; j < size; j++) {
//            BMKTransitStep* transitStep = [plan.steps objectAtIndex:j];
//            int k=0;
//            for(k=0;k<transitStep.pointsCount;k++) {
//                temppoints[i].x = transitStep.points[k].x;
//                temppoints[i].y = transitStep.points[k].y;
//                i++;
//            }}self.lineStatusArr = lineArr;// 通过points构建BMKPolyline
//      BMKPolyline* polyLine = [BMKPolyline polylineWithPoints:temppoints count:planPointCounts];
//      [_mapView addOverlay:polyLine]; // 添加路线overlay
//      delete []temppoints;
//        }[_tableView reloadData];}}
- (void)onGetDrivingRouteResult:(BMKRouteSearch*)searcher result:(BMKDrivingRouteResult*)result errorCode:(BMKSearchErrorCode)error
{NSArray* array = [NSArray arrayWithArray:_mapView.annotations];[_mapView removeAnnotations:array];array = [NSArray arrayWithArray:_mapView.overlays];[_mapView removeOverlays:array];if (error == BMK_SEARCH_NO_ERROR) {BMKDrivingRouteLine* plan = (BMKDrivingRouteLine*)[result.routes objectAtIndex:0];// 计算路线方案中的路段数目int size = [plan.steps count];int planPointCounts = 0;for (int i = 0; i < size; i++) {BMKDrivingStep* transitStep = [plan.steps objectAtIndex:i];if(i==0){RouteAnnotation* item = [[RouteAnnotation alloc]init];item.coordinate = plan.starting.location;item.title = @"起点";item.type = 0;[_mapView addAnnotation:item]; // 添加起点标注}else if(i==size-1){RouteAnnotation* item = [[RouteAnnotation alloc]init];item.coordinate = plan.terminal.location;item.title = @"终点";item.type = 1;[_mapView addAnnotation:item]; // 添加起点标注}//添加annotation节点RouteAnnotation* item = [[RouteAnnotation alloc]init];item.coordinate = transitStep.entrace.location;item.title = transitStep.entraceInstruction;item.degree = transitStep.direction * 30;item.type = 4;[_mapView addAnnotation:item];//轨迹点总数累计planPointCounts += transitStep.pointsCount;}// 添加途经点if (plan.wayPoints) {for (BMKPlanNode* tempNode in plan.wayPoints) {RouteAnnotation* item = [[RouteAnnotation alloc]init];item = [[RouteAnnotation alloc]init];item.coordinate = tempNode.pt;item.type = 5;item.title = tempNode.name;[_mapView addAnnotation:item];}}//轨迹点BMKMapPoint * temppoints = new BMKMapPoint[planPointCounts];int i = 0;for (int j = 0; j < size; j++) {BMKDrivingStep* transitStep = [plan.steps objectAtIndex:j];int k=0;for(k=0;k<transitStep.pointsCount;k++) {temppoints[i].x = transitStep.points[k].x;temppoints[i].y = transitStep.points[k].y;i++;}}// 通过points构建BMKPolylineBMKPolyline* polyLine = [BMKPolyline polylineWithPoints:temppoints count:planPointCounts];[_mapView addOverlay:polyLine]; // 添加路线overlaydelete []temppoints;}
}- (void)onGetWalkingRouteResult:(BMKRouteSearch*)searcher result:(BMKWalkingRouteResult*)result errorCode:(BMKSearchErrorCode)error
{NSArray* array = [NSArray arrayWithArray:_mapView.annotations];[_mapView removeAnnotations:array];array = [NSArray arrayWithArray:_mapView.overlays];[_mapView removeOverlays:array];if (error == BMK_SEARCH_NO_ERROR) {BMKWalkingRouteLine* plan = (BMKWalkingRouteLine*)[result.routes objectAtIndex:0];int size = [plan.steps count];int planPointCounts = 0;for (int i = 0; i < size; i++) {BMKWalkingStep* transitStep = [plan.steps objectAtIndex:i];if(i==0){RouteAnnotation* item = [[RouteAnnotation alloc]init];item.coordinate = plan.starting.location;item.title = @"起点";item.type = 0;[_mapView addAnnotation:item]; // 添加起点标注}else if(i==size-1){RouteAnnotation* item = [[RouteAnnotation alloc]init];item.coordinate = plan.terminal.location;item.title = @"终点";item.type = 1;[_mapView addAnnotation:item]; // 添加起点标注}//添加annotation节点RouteAnnotation* item = [[RouteAnnotation alloc]init];item.coordinate = transitStep.entrace.location;item.title = transitStep.entraceInstruction;item.degree = transitStep.direction * 30;item.type = 4;[_mapView addAnnotation:item];//轨迹点总数累计planPointCounts += transitStep.pointsCount;}//轨迹点BMKMapPoint * temppoints = new BMKMapPoint[planPointCounts];int i = 0;for (int j = 0; j < size; j++) {BMKWalkingStep* transitStep = [plan.steps objectAtIndex:j];int k=0;for(k=0;k<transitStep.pointsCount;k++) {temppoints[i].x = transitStep.points[k].x;temppoints[i].y = transitStep.points[k].y;i++;}}// 通过points构建BMKPolylineBMKPolyline* polyLine = [BMKPolyline polylineWithPoints:temppoints count:planPointCounts];[_mapView addOverlay:polyLine]; // 添加路线overlaydelete []temppoints;}}

3.画路径

我这里实现是跳转到另一个控制器中了,下面是他一些需要的数据

//路线长度
@property (nonatomic,assign) int distance;
//路线消耗时间
@property (nonatomic,assign) int dates;
@property (nonatomic,assign) int hours;
@property (nonatomic,assign) int minutes;
@property (nonatomic,assign) int seconds;
//交通工具数组
@property (nonatomic,strong) NSArray *vehicleInfoArr;
//换乘信息
@property (nonatomic,strong) NSArray *lineStepsArr;
//节点
@property (nonatomic,strong) NSArray *stepsArr;
//轨迹点个数
@property (nonatomic,assign) int planPointCounts;
//轨迹点
@property (nonatomic,strong) NSArray *planStepsArr;

接下来是画路经,关于乘车数据的展示,就是一个tableview上添加了手势,不做解释。

-(void)drawMap
{BMKPointAnnotation* item = [[BMKPointAnnotation alloc]init];item = [_lineInfo.stepsArr firstObject];[_mapView setCenterCoordinate:item.coordinate];[_mapView addAnnotations:_lineInfo.stepsArr];BMKMapPoint* temppoints = (BMKMapPoint *)malloc(sizeof(CLLocationCoordinate2D) * _lineInfo.planPointCounts);int i = 0;for (int j = 0; j < [_lineInfo.planStepsArr count]; j++) {BMKTransitStep* transitStep = [_lineInfo.planStepsArr objectAtIndex:j];int k=0;for(k=0;k<transitStep.pointsCount;k++) {temppoints[i].x = transitStep.points[k].x;temppoints[i].y = transitStep.points[k].y;i++;}}BMKPolyline* polyLine =[BMKPolyline  polylineWithPoints:temppoints count:_lineInfo.planPointCounts];if (nil != polyLine) {[_mapView addOverlay:polyLine]; // 添加路线overlay}free(temppoints);
}- (BMKOverlayView*)mapView:(BMKMapView *)map viewForOverlay:(id<BMKOverlay>)overlay
{if ([overlay isKindOfClass:[BMKPolyline class]]) {BMKPolylineView* polylineView = [[BMKPolylineView alloc] initWithOverlay:overlay];polylineView.fillColor = [[UIColor cyanColor] colorWithAlphaComponent:1];polylineView.strokeColor = [[UIColor blueColor] colorWithAlphaComponent:0.7];polylineView.lineWidth = 3.0;return polylineView;}return nil;
}
// 判断标注类型,来处理
- (BMKAnnotationView*)getRouteAnnotationView:(BMKMapView *)mapview viewForAnnotation:(MyBMKPointAnnotation*)routeAnnotation
{BMKAnnotationView* view = nil;switch (routeAnnotation.type) {case 0:{view = [mapview dequeueReusableAnnotationViewWithIdentifier:@"start_node"];if (view == nil) {view = [[BMKAnnotationView alloc]initWithAnnotation:routeAnnotation reuseIdentifier:@"start_node"];view.image = [UIImage imageWithContentsOfFile:[self getMyBundlePath1:@"images/icon_nav_start.png"]];view.centerOffset = CGPointMake(0, -(view.frame.size.height * 0.5));view.canShowCallout = TRUE;}view.annotation = routeAnnotation;}break;case 1:{view = [mapview dequeueReusableAnnotationViewWithIdentifier:@"end_node"];if (view == nil) {view = [[BMKAnnotationView alloc]initWithAnnotation:routeAnnotation reuseIdentifier:@"end_node"];view.image = [UIImage imageWithContentsOfFile:[self getMyBundlePath1:@"images/icon_nav_end.png"]];view.centerOffset = CGPointMake(0, -(view.frame.size.height * 0.5));view.canShowCallout = TRUE;}view.annotation = routeAnnotation;}break;case 2:{view = [mapview dequeueReusableAnnotationViewWithIdentifier:@"bus_node"];if (view == nil) {view = [[BMKAnnotationView alloc]initWithAnnotation:routeAnnotation reuseIdentifier:@"bus_node"];view.image = [UIImage imageWithContentsOfFile:[self getMyBundlePath1:@"images/icon_nav_bus.png"]];view.canShowCallout = TRUE;}view.annotation = routeAnnotation;}break;case 3:{view = [mapview dequeueReusableAnnotationViewWithIdentifier:@"rail_node"];if (view == nil) {view = [[BMKAnnotationView alloc]initWithAnnotation:routeAnnotation reuseIdentifier:@"rail_node"];view.image = [UIImage imageWithContentsOfFile:[self getMyBundlePath1:@"images/icon_nav_rail.png"]];view.canShowCallout = TRUE;}view.annotation = routeAnnotation;}break;case 4:{view = [mapview dequeueReusableAnnotationViewWithIdentifier:@"route_node"];if (view == nil) {view = [[BMKAnnotationView alloc]initWithAnnotation:routeAnnotation reuseIdentifier:@"route_node"];view.canShowCallout = TRUE;} else {[view setNeedsDisplay];}UIImage* image = [UIImage imageWithContentsOfFile:[self getMyBundlePath1:@"images/icon_direction.png"]];view.image = [image imageRotatedByDegrees:routeAnnotation.degree];view.annotation = routeAnnotation;}break;case 5:{view = [mapview dequeueReusableAnnotationViewWithIdentifier:@"waypoint_node"];if (view == nil) {view = [[BMKAnnotationView alloc]initWithAnnotation:routeAnnotation reuseIdentifier:@"waypoint_node"];view.canShowCallout = TRUE;} else {[view setNeedsDisplay];}UIImage* image = [UIImage imageWithContentsOfFile:[self getMyBundlePath1:@"images/icon_nav_waypoint.png"]];view.image = [image imageRotatedByDegrees:routeAnnotation.degree];view.annotation = routeAnnotation;}break;default:break;}return view;
}- (BMKAnnotationView *)mapView:(BMKMapView *)view viewForAnnotation:(id <BMKAnnotation>)annotation
{if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {return [self getRouteAnnotationView:view viewForAnnotation:(MyBMKPointAnnotation *)annotation];}return nil;
}- (UIImage*)imageRotatedByDegrees:(CGFloat)degrees
{CGFloat width = CGImageGetWidth(self.CGImage);CGFloat height = CGImageGetHeight(self.CGImage);CGSize rotatedSize;rotatedSize.width = width;rotatedSize.height = height;UIGraphicsBeginImageContext(rotatedSize);CGContextRef bitmap = UIGraphicsGetCurrentContext();CGContextTranslateCTM(bitmap, rotatedSize.width/2, rotatedSize.height/2);CGContextRotateCTM(bitmap, degrees * M_PI / 180);CGContextRotateCTM(bitmap, M_PI);CGContextScaleCTM(bitmap, -1.0, 1.0);CGContextDrawImage(bitmap, CGRectMake(-rotatedSize.width/2, -rotatedSize.height/2, rotatedSize.width, rotatedSize.height), self.CGImage);UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();UIGraphicsEndImageContext();return newImage;
}


四、另一种方法

///
if ([annotation isKindOfClass:[SiteAnnotation class]]) {static NSString *identifier = @"MKAnnotationView";BMKAnnotationView *pin = [mapView dequeueReusableAnnotationViewWithIdentifier:identifier];if (pin == nil) {pin = [[BMKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];//在图中我们可以看到图标的上方,有个气泡弹窗里面写着当前用户的位置所在地pin.image = [UIImage imageNamed:@"default_marker.png"];}pin.annotation = annotation;pin.paopaoView = [[BMKActionPaopaoView alloc]initWithCustomView:[[UIView alloc] init]];return pin;} 







这篇关于IOS百度地图自定义大头针和气泡的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/372223

相关文章

百度/小米/滴滴/京东,中台架构比较

小米中台建设实践 01 小米的三大中台建设:业务+数据+技术 业务中台--从业务说起 在中台建设中,需要规范化的服务接口、一致整合化的数据、容器化的技术组件以及弹性的基础设施。并结合业务情况,判定是否真的需要中台。 小米参考了业界优秀的案例包括移动中台、数据中台、业务中台、技术中台等,再结合其业务发展历程及业务现状,整理了中台架构的核心方法论,一是企业如何共享服务,二是如何为业务提供便利。

无人叉车3d激光slam多房间建图定位异常处理方案-墙体画线地图切分方案

墙体画线地图切分方案 针对问题:墙体两侧特征混淆误匹配,导致建图和定位偏差,表现为过门跳变、外月台走歪等 ·解决思路:预期的根治方案IGICP需要较长时间完成上线,先使用切分地图的工程化方案,即墙体两侧切分为不同地图,在某一侧只使用该侧地图进行定位 方案思路 切分原理:切分地图基于关键帧位置,而非点云。 理论基础:光照是直线的,一帧点云必定只能照射到墙的一侧,无法同时照到两侧实践考虑:关

【前端学习】AntV G6-08 深入图形与图形分组、自定义节点、节点动画(下)

【课程链接】 AntV G6:深入图形与图形分组、自定义节点、节点动画(下)_哔哩哔哩_bilibili 本章十吾老师讲解了一个复杂的自定义节点中,应该怎样去计算和绘制图形,如何给一个图形制作不间断的动画,以及在鼠标事件之后产生动画。(有点难,需要好好理解) <!DOCTYPE html><html><head><meta charset="UTF-8"><title>06

安卓链接正常显示,ios#符被转义%23导致链接访问404

原因分析: url中含有特殊字符 中文未编码 都有可能导致URL转换失败,所以需要对url编码处理  如下: guard let allowUrl = webUrl.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else {return} 后面发现当url中有#号时,会被误伤转义为%23,导致链接无法访问

自定义类型:结构体(续)

目录 一. 结构体的内存对齐 1.1 为什么存在内存对齐? 1.2 修改默认对齐数 二. 结构体传参 三. 结构体实现位段 一. 结构体的内存对齐 在前面的文章里我们已经讲过一部分的内存对齐的知识,并举出了两个例子,我们再举出两个例子继续说明: struct S3{double a;int b;char c;};int mian(){printf("%zd\n",s

Spring 源码解读:自定义实现Bean定义的注册与解析

引言 在Spring框架中,Bean的注册与解析是整个依赖注入流程的核心步骤。通过Bean定义,Spring容器知道如何创建、配置和管理每个Bean实例。本篇文章将通过实现一个简化版的Bean定义注册与解析机制,帮助你理解Spring框架背后的设计逻辑。我们还将对比Spring中的BeanDefinition和BeanDefinitionRegistry,以全面掌握Bean注册和解析的核心原理。

【iOS】MVC模式

MVC模式 MVC模式MVC模式demo MVC模式 MVC模式全称为model(模型)view(视图)controller(控制器),他分为三个不同的层分别负责不同的职责。 View:该层用于存放视图,该层中我们可以对页面及控件进行布局。Model:模型一般都拥有很好的可复用性,在该层中,我们可以统一管理一些数据。Controlller:该层充当一个CPU的功能,即该应用程序

Oracle type (自定义类型的使用)

oracle - type   type定义: oracle中自定义数据类型 oracle中有基本的数据类型,如number,varchar2,date,numeric,float....但有时候我们需要特殊的格式, 如将name定义为(firstname,lastname)的形式,我们想把这个作为一个表的一列看待,这时候就要我们自己定义一个数据类型 格式 :create or repla

HTML5自定义属性对象Dataset

原文转自HTML5自定义属性对象Dataset简介 一、html5 自定义属性介绍 之前翻译的“你必须知道的28个HTML5特征、窍门和技术”一文中对于HTML5中自定义合法属性data-已经做过些介绍,就是在HTML5中我们可以使用data-前缀设置我们需要的自定义属性,来进行一些数据的存放,例如我们要在一个文字按钮上存放相对应的id: <a href="javascript:" d

一步一步将PlantUML类图导出为自定义格式的XMI文件

一步一步将PlantUML类图导出为自定义格式的XMI文件 说明: 首次发表日期:2024-09-08PlantUML官网: https://plantuml.com/zh/PlantUML命令行文档: https://plantuml.com/zh/command-line#6a26f548831e6a8cPlantUML XMI文档: https://plantuml.com/zh/xmi