2012-02-16 31 views
0

點擊展開按鈕從註釋後後顯示信息當前地圖的快照,你會最終有一個名爲查看信息。在此屏幕的左上角,有一個小圖像,它是您當前位置的快照。有誰知道如何從地圖和顯示信息畫面 獲取快照有這樣的圖像,讓您可以輕鬆地知道我在說什麼 請幫幫忙,所有的答案都在這裏歡迎。 enter image description here如何點擊公開內容,從註釋

回答

0

你會想使用CoreGraphics中呈現地圖的圖像。

if (UIGraphicsBeginImageContextWithOptions != NULL) { 
    UIGraphicsBeginImageContextWithOptions(frameYouWantToCopy.size, NO, 0.0); 
} 
else { 
    UIGraphicsBeginImageContext(frameYouWantToCopy.size); 
} 
[mapView.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *result = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

return result; 
+0

感謝您的評論。現在處理它。 – tranvutuan 2012-02-16 19:05:39

+0

我試過了,圖像的大小不太好。我所做的是** UIGraphicsBeginImageContextWithOptions(CGSizeMake(32,32),NO,0.0); ** – tranvutuan 2012-02-16 19:38:22

+0

我試圖和圖像的大小不是處於良好shape.The長度爲兩倍的高度和它沒有顯示的註釋它......我所做的是* UIGraphicsBeginImageContextWithOptions(CGSizeMake(32,32),NO,0.0); * ...其餘的是從您的評論一樣。 – tranvutuan 2012-02-16 19:52:36

0

我已經得到了解決這一點 當你點擊信息按鈕剛剛設置地圖的中心。並從那裏拍攝圖像 我到目前爲止所做的是 在.h中拍攝了一個圖像mapImageview,並使用該imageview存儲了註釋的圖像 首先記住已丟棄的圖釘的座標 ,然後僅居中通過調用函數

-(void)setMaptocentre:(double)lat (double)long 
{ 
    MKCoordinateRegion region; 
    region.center.latitude=lat; 
    region.center.longitude=long; 

    MKCoordinateSpan span; 
    span.latitudeDelta=10; 
    span.longitudeDelta=10; 
    region.span =span; 
    [MapView setRegion:region animated:YES]; 
} 

-(IBAction)infoPressed:(id)sender 
{ 
    [self setMaptocentre: rememberedLat rememberdLong]; 
    //here the rememberedlat and rememberedLong are the latitude and longitude you have 
    // saved at the time of pin drop. the function brings the pin to centre of map 
    // and then does the following part to take the image, where it includes the pin 

    UIGraphicsBeginImageContext(CGRectMake(150, 200, 100, 100).size); 
    CGContextRef c = UIGraphicsGetCurrentContext(); 
    CGContextTranslateCTM(c,-105, -130); 
    [self.view.layer renderInContext:c]; 
    UIImage* viewImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    NSData *imageData = UIImagePNGRepresentation(viewImage); 
    mapImageview.image = [UIImage imageWithData:imageData]; 
} 

我知道你會得到答案uptill,但現在他人的震動區域,我在這裏張貼 感謝