iOS 百度地图_自定义Annotation大头针_修改大头针图片

来源:互联网 发布:linux locate命令 编辑:程序博客网 时间:2024/05/21 17:02

在使用百度地图, 如果需要添加大头针, 但是图片不想用系统的, 那么怎么修改呢??

  • 1:在代码中实现BMKMapViewDelegate
  • 2:在- (void)viewWillAppear:(BOOL)animated方法中设置代理到self, 记得到这个方法内 在其他方法中如viewDidLoad中有时会出现莫名其妙的诡异问题, 可看百度地图_回调不走_onGetGeoCodeResult不执行
    同时记得在- (void)viewWillDisappear:(BOOL)animated中记得置为nil, 不然会内存泄露, 释放不掉
- (void)viewWillAppear:(BOOL)animated{    [super viewWillAppear:animated];    mapView.delegate = self;    }- (void)viewWillDisappear:(BOOL)animated{    [super viewWillDisappear:animated];    mapView.delegate = nil;}
  • 3:重写- (BMKAnnotationView )mapView:(BMKMapView )mapView viewForAnnotation:(id)annotation{
    方法:
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id<BMKAnnotation>)annotation{        BMKPinAnnotationView *newAnnotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"myAnnotation"];        newAnnotationView.pinColor = BMKPinAnnotationColorPurple;        newAnnotationView.animatesDrop = YES;// 设置该标注点动画显示        newAnnotationView.annotation=annotation;        newAnnotationView.image = [UIImage imageNamed:@"home_test"];   //把大头针换成别的图片        newAnnotationView.size = CGSizeMake(23, 23);        return newAnnotationView;}

OK了, 这样图片就改变了

0 0
原创粉丝点击