在使用百度地图, 如果需要添加大头针, 但是图片不想用系统的, 那么怎么修改呢??
1:在代码中实现BMKMapViewDelegate2:在- (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了, 这样图片就改变了