自定义点标记图标
功能场景
开发者可根据app风格使用自定义的标记样式,更加符合业务场景和特色。
//mapopen-website-wiki.bj.bcebos.com/demos/AndroidVideos/自定义标注点.mp4
icon(BitmapDescriptor icon)
position(LatLng position)
addOverlay(OverlayOptions options)
fromResource(int resourceId)
根据资源Id创建不适配设备像素密度的bitmap描述信息
setIcon(BitmapDescriptor bitmap)
MarkerOptions markerOptions = new MarkerOptions()
.position(center)//Marker经纬度
.icon(mBitmapDescriptorStart);
mMarker = (Marker) mBaiduMap.addOverlay(markerOptions);
复制成功
mMarker.setIcon(mBitmapDescriptorEnd);
//mapopen-website-wiki.bj.bcebos.com/demos/iosVideos/iOS自定义标注图标.mov
- (id)initWithAnnotation:(id<BMKAnnotation>)annotationreuseIdentifier:(NSString*)reuseIdentifier;
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id<BMKAnnotation>)annotation;
/** 根据anntation生成对应的annotationView. */
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id<BMKAnnotation>)annotation {
BMKCustomAnnotationView *annotationView = (BMKCustomAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:annotationViewIdentifier];
if (!annotationView) {
/**
初始化并返回一个annotationView
@param annotation 关联的annotation对象
@param reuseIdentifier 如果要重用view,传入一个字符串,否则设为nil,建议重用view
@return 初始化成功则返回annotationView,否则返回nil
*/
annotationView = [[BMKCustomAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annotationViewIdentifier];
}
return annotationView;
}
// 自定义标注代码
/**
初始化并返回一个annotationView
@param annotation 关联的annotation对象
@param reuseIdentifier 如果要重用view,传入一个字符串,否则设为nil,建议重用view
@return 初始化成功则返回annotation view,否则返回nil
*/
- (id)initWithAnnotation:(id<BMKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
if (self) {
self.frame = CGRectMake(0, 0, 32, 32);
UIImageView *annotationImage = [[UIImageView alloc] initWithFrame:self.frame];
annotationImage.animationImages = @[[UIImage imageNamed:@"greenAnimationIcon"], [UIImage imageNamed:@"blackAnimationIcon"], [UIImage imageNamed:@"redAnimationIcon"]];
annotationImage.animationDuration = 0.5 * 3;
annotationImage.animationRepeatCount = 0;
[annotationImage startAnimating];
[self addSubview:annotationImage];
}
return self;
}
复制成功