gpt4 book ai didi

ios - 来自 MapView Annotation-iOS 的缩略图

转载 作者:行者123 更新时间:2023-11-28 22:48:12 25 4
gpt4 key购买 nike

如何从 mapView 获取缩略图,如下图红色矩形框所示。 enter image description here

UIView *thumbnailContainer=[[UIView alloc]initWithFrame:CGRectMake(10,10,64,64)];
thumbnailContainer.clipsToBounds=YES;
thumbnailContainer.layer.borderColor=[UIColor colorWithWhite:0 alpha:0.5].CGColor;
thumbnailContainer.layer.cornerRadius=3;
thumbnailContainer.layer.borderWidth=1;

Annotation *annotation1=[[Annotation alloc]init];
annotation1.coordinate = CLLocationCoordinate2DMake(29.7189214,-95.33916);
annotation1.title = @"University of Houston";
annotation1.subtitle = @"4800 Calhoun Rd,Houston";
MKMapView *mapView2=[[MKMapView alloc]initWithFrame:CGRectMake(0, 0, 150, 150)];
mapView2.userInteractionEnabled=NO;
mapView2.centerCoordinate=[annotation1 coordinate];
[mapView2 addAnnotation:annotation1];
//annPoint=[self.mapView convertCoordinate:annotation1.coordinate toPointToView:self.mapView];

MKCoordinateRegion region=MKCoordinateRegionMakeWithDistance(mapView2.centerCoordinate, 150, 150);
mapView2.region=region;
mapView2.transform=CGAffineTransformMakeScale(0.75, 0.75);
mapView2.layer.position=CGPointMake(thumbnailContainer.bounds.size.width/2,thumbnailContainer.bounds.size.height/2+10);
[thumbnailContainer addSubview:mapView2];

最佳答案

使用按比例缩小的 map View 怎么样?我不认为从 map View 的渲染层创建缩略图是一个很好的解决方案,因为它需要首先以所需的缩放比例加载 map ,然后,为什么不直接显示这张 map 而不是制作它的图像? :D 这是我要使用的代码。

    Annotation *yourAnnotation = [[Annotation alloc] init];

UIView *thumbnailContainer = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 64, 64)];
thumbnailContainer.clipsToBounds = YES;
thumbnailContainer.layer.borderColor = [UIColor colorWithWhite:0 alpha:0.5].CGColor;
thumbnailContainer.layer.cornerRadius = 3;
thumbnailContainer.layer.borderWidth = 1;

MKMapView *thumbnailMap = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 150, 150)];
thumbnailMap.userInteractionEnabled = NO;
thumbnailMap.centerCoordinate = [yourAnnotation coordinate];
[thumbnailMap addAnnotation:yourAnnotation];

MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(thumbnailMap.centerCoordinate, 150, 150);
thumbnailMap.region = region;
thumbnailMap.transform = CGAffineTransformMakeScale(0.75, 0.75);
//we add 10 pixels on the y coordinate, to center the pin in the view. Moreover it will hide the "legal" label of the map view.
thumbnailMap.layer.position = CGPointMake(thumbnailContainer.bounds.size.width / 2, thumbnailContainer.bounds.size.height / 2 + 10);
[thumbnailContainer addSubview:thumbnailMap];

看起来像这样:enter image description here

关于ios - 来自 MapView Annotation-iOS 的缩略图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12643857/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com