如何从mapView获取缩略图,如下图中的红色矩形框所示。
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];
答案 0 :(得分:1)
有可能它是地图的截图,因为iOS中的任何实时地图都在底部角落包含Google地图徽标(
为了做到这一点,你需要在引脚所在的映射中计算出rect,然后使用UIGraphicsContent()和这些函数来截取视图。然后,您可以将该图像放入UIImageView中,以便用户可以显示它。
UIGraphicsBeginImageContext(mapRect);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
或者,您可以使用Google Maps Static API,它允许您使用指定的纬度和经度值接收特定位置的地图图片。
https://developers.google.com/maps/documentation/staticmaps/
答案 1 :(得分:1)
使用缩小的地图视图怎么样?我不认为从地图视图的渲染层创建缩略图图像是一个很好的解决方案,因为它需要首先以所需的缩放加载地图,然后,为什么不直接显示此地图而不是制作一张图片吗? :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];
看起来像是: