分篇介绍最新百度地图相关应用
一、环境配置:
https://www.jianshu.com/p/be592ed98ebf
二、显示与定位:
https://www.jianshu.com/p/154c7840ffa5
三、根据经纬度描点:
https://www.jianshu.com/p/a4065c3f0457
四、大头针与气泡:
https://www.jianshu.com/p/bb8f8f3c1ef1
五、给大头针加tag值:
https://www.jianshu.com/p/6023465da2e7
六、问题处理:
https://www.jianshu.com/p/c8b1449efea7
本篇介绍给大头针加tag值!
项目demo:
https://github.com/Dongxk/XKBMKMap.git
本篇效果:
方法:
在- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation方法中替换掉原先的BMKAnnotationView;
#pragma mark --- BMKMapViewDelegate
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id<BMKAnnotation>)annotation{
if ([annotation isKindOfClass:[self.pointAnnotation class]]) {
//数组对应大头针
paopaoIndex++;
UIView *paopaoView = [UIView new];
static NSString *identifier = @"XKAnnotationView";
//自定义的XKAnnotationView 替换掉原先的BMKAnnotationView
XKAnnotationView *annotationView = [[XKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier customView:paopaoView WithData: self.pointArray[paopaoIndex - 1] WithTag:1000 + paopaoIndex];
return annotationView;
}else{
//定位大头针
}
return nil;
}
自定义AnnotationView
- (id)initWithAnnotation:(id<BMKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier customView:(UIView *)detailView WithData:(NSDictionary *)dataDict WithTag:(NSInteger)tag{
if (self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier]) {
if (self) {
[self setBounds:CGRectMake(0, 0, 100.f, 100.f)];
self.canShowCallout = YES;
self.centerOffset = CGPointMake(0, 0); //设置中心点偏移
detailView.tag = tag;
[self configCellWithData:dataDict];
[self addSubview: detailView];
}
}
return self;
}
具体请看demo:
demo