百度地图|百度地图 --大头针与气泡
分篇介绍最新百度地图相关应用
一、环境配置:
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
本篇介绍大头针与气泡!
项目demo: https://github.com/Dongxk/XKBMKMap.git
效果:
文章图片
1、修改大头针属性
#pragma mark ---BMKMapViewDelegate
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id)annotation{//对大头针以及气泡进行一些设置
if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {static NSString *identifier = @"BMKAnnotationView";
BMKAnnotationView *annotationView = [[BMKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
//修改大头针图片
annotationView.image = [UIImage imageNamed:@"location"];
//是否允许点击
annotationView.canShowCallout = YES;
// 等一些其他属性设置
///.....
return annotationView;
}
return nil;
}
2、 点击大头针
#pragma mark --- 点击大头针事件
- (void)mapView:(BMKMapView *)mapView didSelectAnnotationView:(BMKAnnotationView *)view{//[mapView deselectAnnotation:view.annotation animated:NO];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"您点击了大头针" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
[alert show];
}
3、 点击气泡:
在此方法中可以获取到点击了大头针以及泡泡对应的信息:
/// 要显示的标题;注意:如果不设置title,无法点击annotation,也无法使用回调函数;
@property (copy) NSString *title;
/// 要显示的副标题
@property (copy) NSString *subtitle;
但是如果对应一个接口返回的json数据,如果要回去点击了某条数据对应的id呢,该怎么办?怎么给大头针加唯一的标识? 百度地图不支持直接添加tag值。 所以这里自定义了一个大头针赋值方法,如你也有此需求,请看下一篇。
#pragma mark --- 点击气泡事件
- (void)mapView:(BMKMapView *)mapView annotationViewForBubble:(BMKAnnotationView *)view{UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"您点击了泡泡" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
[alert show];
}
【百度地图|百度地图 --大头针与气泡】demo
推荐阅读
- 拿着旧地图,找不到新大陆
- 百度云极速下载,来体验飞的感觉,还可以看最新动漫的百度云视频哦
- 地图|地图 旅行 菜系
- 虎刺梅
- 假如给我三天光明
- 儿时的年味/记忆中的年味
- 斗罗大陆1(第39集)百度云下载【1080熟肉共享】完整版资源
- 嘘,小声点
- 为什么你有那么多百度微积分(你的微积分是哪里来的?)
- 百度地图多边形时候射线问题2018-09-01