0

下の図の赤い四角形のボックスに示されているように、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];
4

2 に答える 2

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];

次のようになります。ここに画像の説明を入力

于 2012-09-28T17:16:09.383 に答える
1

iOS のライブ マップには、下隅に Google マップのロゴが含まれているため (

これを行うには、ピンが存在するマップ内の四角形を作成し、UIGraphicsContent() などの関数を使用してビューのスクリーンショットを作成する必要があります。次に、その画像を UIImageView に入れて、ユーザーが表示できるようにします。

UIGraphicsBeginImageContext(mapRect);    
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

または、指定された緯度と経度の値を使用して、特定の場所で地図の写真を受け取ることができる Google Maps Static API を使用することもできます。

https://developers.google.com/maps/documentation/staticmaps/

于 2012-09-28T17:10:23.933 に答える