我是最近接触的百度读图开发,百度地图的相关sdk api开发写的很简单,有不少都是写的不是很详细,可是若是咱们想深究就会遇到不少问题,有许多咱们想得到都东西每每都无法得到。直接步入正题吧,遇到问题以下:git
一:我新申请的key,为啥没有用?地图无法加载,这个颇有多是你申请的key,有了,可是没有认证开发者,这就致使你的key没有用,地图没有加载出来,这个问题困扰了我好久才发现。
api
二:第一次使用百度地图的时候,必要的就是看Demo怎么使用这些方法。在使用官方Demo的时候地图真机测试就会出错,这个错误我大概记得,一个别忘申请新的key,二,别忘了选择证书,每每这个会致使错误app
CodeSign error: code signing is required for product type 'Application' in SDK 'iOS 9.2'测试
这个就是证书没有选择的错误ui
三:按照官方文档建立地图后以及写了相关方法,这里我就很少说了,值得注意的是若是咱们若是想获取当前的经纬度的话就得引入定位服务,经过atom
[self.myLocationService startUserLocationService];spa
设置BMKLocationService 代理
的代理人经过代理方法开启定位服务后就会执行updatelocation方法获取当前的经纬度,设置为地图中心点。值得注意的事,要在这中止定位服务,要否则的你的如何移动地图,地图的中心点会在隔几秒会回到原处。这是我我的的方法,不对的话,给我提出来。同事显示定位的图层code
self.myLocationService = [[BMKLocationService alloc]init]; [self.myLocationService startUserLocationService];//开始定位服务 // self.mapView.showsUserLocation = NO; // self.mapView.userTrackingMode = BMKUserTrackingModeFollow; // self.mapView.showsUserLocation = YES; self.myMapView.showsUserLocation = NO; self.myLocationService.delegate = self; self.myMapView.userTrackingMode = BMKUserTrackingModeFollow;//设置定位的状态 self.myMapView.showsUserLocation = YES;//显示定位图层
四:自定义定位图层的图标,也许大家应该使用过百度的导航服务,仔细的人就会发现,地位图标是跟随样式,若是要由于这个图标旋转,就引入导航的SDK那就有点大材小用,致使APP的包过大,其实在咱们能够重写这个orm
BMKLocationViewDisplayParam
这个类对象,根据将其中的imagename改为你的那个替换图片就行
BMKLocationViewDisplayParam *param = [[BMKLocationViewDisplayParam alloc] init]; param.isRotateAngleValid = YES; param.isAccuracyCircleShow = YES; param.locationViewImgName = @"icon_center_point1"; param.locationViewOffsetX = 0; param.locationViewOffsetY = 0; [self.myMapView updateLocationViewWithParam:param];
icon_center_poin这个是boudle资源中的定位图层的那个图片名称,能够换成你想要的图片名称就行
五:自定义大投标,这个就须要你本身写一个类继承
BMKAnnotationView
这个类就行,而后就在其中建立你想要的一些信息,也能够建立paopaoView这个就是你点击这个大头针弹出的时候,你就能够自定义视图,想展现什么内容就展现什么内容。这个是我自定义大投标的的那个类。m文件中主要的方法
@interface LL_MapViewAnnotationView() @property(nonatomic,strong)UIImageView *myHeadImageView; @end @implementation LL_MapViewAnnotationView @synthesize headViewName; -(id)initWithAnnotation:(id<BMKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier]; if (self) { [self setBounds:CGRectMake(0, 0, 50, 55)]; UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 50, 55)]; [button setBackgroundImage:[UIImage imageNamed:@"btn_肯定"] forState:UIControlStateNormal]; [self addSubview:button]; self.myHeadImageView = [[UIImageView alloc]initWithFrame:CGRectMake(2, 5, 45, 45)]; self.myHeadImageView.clipsToBounds = YES; self.myHeadImageView.layer.cornerRadius = 22.5; [button addSubview:self.myHeadImageView]; button.userInteractionEnabled = NO; BMKActionPaopaoView *paopaoView = [[BMKActionPaopaoView alloc]initWithCustomView:[self createPaopaoViewWithModel]]; self.paopaoView = paopaoView; } return self; } -(UIView *)createPaopaoViewWithModel { UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 250,143)]; UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 1, 143)]; [view addSubview:lineView]; UIView *allView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 250, 143)]; [lineView addSubview:allView]; // view.alpha = 0.4; allView.backgroundColor = [[Unity getColor:@"#000000"] colorWithAlphaComponent:0.4]; //头像 UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(15, 8, 100, 100)]; [imageView setImage:[UIImage imageNamed:@"img1"]]; imageView.clipsToBounds = YES; imageView.layer.cornerRadius = 50; [view addSubview:imageView]; //删除button UIButton *deleateBut =[[UIButton alloc]initWithFrame:CGRectMake(view.frame.size.width -5-20, 8, 20, 20)]; [deleateBut setBackgroundImage:[UIImage imageNamed:@"ic_btn_Deleate"] forState:UIControlStateNormal]; deleateBut.tag = 1001; [view addSubview:deleateBut]; [deleateBut addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchDown]; //距离Lable UILabel *distence = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(imageView.frame)+20, 14, 101, 20)]; [view addSubview:distence]; NSMutableAttributedString *string = [[NSMutableAttributedString alloc]init]; //添加图片的 NSTextAttachment *attach = [[NSTextAttachment alloc]init]; attach.image = [UIImage imageNamed:@"ic_find_Distence"]; attach.bounds =CGRectMake(0, -5, 30, 20); NSAttributedString *attachString = [NSAttributedString attributedStringWithAttachment:attach]; [string appendAttributedString:attachString]; NSString *tempStr = [NSString stringWithFormat:@" 距离"]; NSMutableAttributedString *textStr = [[NSMutableAttributedString alloc]initWithString:tempStr]; [textStr addAttribute:NSForegroundColorAttributeName value:[Unity getColor:@"#FFFFFF"] range:NSMakeRange(0, tempStr.length)]; [textStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:13] range:NSMakeRange(0, tempStr.length)]; [string appendAttributedString:textStr]; distence.attributedText = string; //距离数量Lable UILabel *distenceNum = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMinX(distence.frame), CGRectGetMaxY(distence.frame), view.frame.size.width-CGRectGetMinX(distence.frame)-40, 30)]; NSString *distenceNumText = [NSString stringWithFormat:@"153 米"]; NSMutableAttributedString *distenceString = [[NSMutableAttributedString alloc]initWithString:distenceNumText]; [distenceString addAttribute:NSForegroundColorAttributeName value:[Unity getColor:@"#FFFFFF"] range:NSMakeRange(0, 3)]; [distenceString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:19] range:NSMakeRange(0, 3)]; [distenceString addAttribute:NSForegroundColorAttributeName value:[Unity getColor:@"#FDB100"] range:NSMakeRange(5, 1)]; [distenceString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:11] range:NSMakeRange(5, 1)]; distenceNum.attributedText = distenceString; distenceNum.textAlignment = NSTextAlignmentCenter; [view addSubview:distenceNum]; UIView *downLoadView = [[UIView alloc]initWithFrame:CGRectMake(0, 90, 250, 53)]; downLoadView.backgroundColor = [[Unity getColor:@"#4D4D4D"] colorWithAlphaComponent:0.5]; [view addSubview:downLoadView]; UIView *sexBackView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 35, 53)]; [sexBackView setBackgroundColor:[Unity getColor:@"#FFB300"]]; [downLoadView addSubview:sexBackView]; UIImageView *sexImageView = [[UIImageView alloc]initWithFrame:CGRectMake(5, 14, 25, 25)]; [sexBackView addSubview:sexImageView]; sexImageView.clipsToBounds = YES; sexImageView.layer.cornerRadius = 12.5; [sexBackView addSubview:sexImageView]; [sexImageView setImage:[UIImage imageNamed:@"ic_男"]]; //姓名lable UILabel *nameLable = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(sexBackView.frame)+12, 8, 120, 25)]; nameLable.textColor = [Unity getColor:@"#FFFFFF"]; nameLable.font = [UIFont systemFontOfSize:18]; nameLable.text = @"张三"; [downLoadView addSubview:nameLable]; //个性签名 UILabel *mySignText = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMinX(nameLable.frame), CGRectGetMaxY(nameLable.frame), 120, 20)]; mySignText.textColor = [Unity getColor:@"#FFFFFF"]; mySignText.font = [UIFont systemFontOfSize:12]; mySignText.text = @"个性签名"; [downLoadView addSubview:mySignText]; //查看button UIButton *lookButton = [[UIButton alloc]initWithFrame:CGRectMake(downLoadView.frame.size.width-10-80, 20, 80, 30)]; [lookButton setImage:[UIImage imageNamed:@"ic_look_detail"] forState:UIControlStateNormal]; [lookButton setTitle:@"查看" forState:UIControlStateNormal]; [lookButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; lookButton.tag = 1002; [lookButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchDown]; [downLoadView addSubview:lookButton]; return view; }
六:在建立大头针的时候也很简单和官方的说法同样,值得注意的就是添加其中的一些方法就行
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation { NSString *AnnotationViewID = @"AnimatedAnnotation"; LL_MapViewAnnotationView *annotationView = nil; if (annotationView == nil) { annotationView = [[LL_MapViewAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:AnnotationViewID]; [annotationView upHeadViewNameWithString:@"img1"]; annotationView.myBlock = ^(NSInteger tag){ switch (tag) { case 1001: { NSLog(@"删除按钮"); } break; case 1002: { NSLog(@"查看按钮"); } break; default: break; } }; } return annotationView; }
这段代码是加大头针的方法,里面不要管别的,其余的不用想,想多了就很麻烦,我以前就是那样觉得经过什么方法调用就行,其实这个跟tableView同样给个数据,设定高度,cell的数量,而后就是在代理方法中写返回的cell的样式就行
BMKPointAnnotation* annotation = [[BMKPointAnnotation alloc]init]; CLLocationCoordinate2D coor; coor.latitude = 39.915; coor.longitude = 116.404; annotation.coordinate = coor; annotation.title = @"这里是北京"; [self.myMapView addAnnotation:annotation];
其实还有别的问题,明天再说,今天有点累了,要睡觉了