您的位置:首页 > 移动开发 > IOS开发

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

2016-01-13 16:35 537 查看

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

1:在代码中实现BMKMapViewDelegate

2:在- (void)viewWillAppear:(BOOL)animated方法中设置代理到self, 记得到这个方法内 在其他方法中如viewDidLoad中有时会出现莫名其妙的诡异问题, 可看百度地图_回调不走_onGetGeoCodeResult不执行

同时记得在- (void)viewWillDisappear:(BOOL)animated中记得置为nil, 不然会内存泄露, 释放不掉

[code]- (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{

方法:

[code]- (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了, 这样图片就改变了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: