IOS 設置百度地圖自定義標注圖片,自定義泡泡

cnffe 9年前發布 | 3K 次閱讀 C/C++ IOS

#pragma mark - BMKMapViewDelegate

// 根據anntation生成對應的View

  • (BMKAnnotationView )mapView:(BMKMapView )mapView viewForAnnotation:(id <BMKAnnotation>)annotation

{

//普通annotation

NSString *AnnotationViewID = @"ClusterMark";

ClusterAnnotation *cluster = (ClusterAnnotation*)annotation;

ClusterAnnotationView *annotationView = [[ClusterAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID];

annotationView.size = cluster.size;

annotationView.canShowCallout = NO;//在點擊大頭針的時候會彈出那個黑框框

annotationView.draggable = NO;//禁止標注在地圖上拖動

annotationView.annotation = cluster;

// annotationView.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:annotation.subtitle]]];

annotationView.centerOffset=CGPointMake(0,0);



UIView *viewForImage=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 110, 110)];

UIImageView *imageview=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 110, 110)];

[imageview setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:annotation.subtitle]]]];

imageview.layer.masksToBounds=YES;

imageview.layer.cornerRadius = 10;

[viewForImage addSubview:imageview];

annotationView.image=[self getImageFromView:viewForImage];

return annotationView;

}

-(UIImage )getImageFromView:(UIView )view{

UIGraphicsBeginImageContext(view.bounds.size);

[view.layer renderInContext:UIGraphicsGetCurrentContext()];

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return image;

}

//氣泡框左側顯示的View,可自定義 annotationView.leftCalloutAccessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_location.png"]]; //氣泡框右側顯示的View 可自定義 annotationView.rightCalloutAccessoryView =selectButton; //讓標注在進入界面時就處于彈出氣泡框的狀態 [annotationView setSelected:YES animated:YES];

</pre>

 本文由用戶 cnffe 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!