百度地图|百度地图 --大头针与气泡

分篇介绍最新百度地图相关应用
一、环境配置:
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

    推荐阅读