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

24 篇文章 0 订阅
5 篇文章 0 订阅

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

  • 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
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值