簡體   English   中英

MKTileOverlay 中的 MKMapSnapshotter 出現位移

[英]MKMapSnapshotter in MKTileOverlay appears displaced

我正在使用以下代碼覆蓋MKTileOverlayloadTileAtPath:result:方法。 它只是將MKTileOverlayPath轉換為 MKMapRect,然后使用MKMapSnapshotter拍攝正在查看的地圖區域的快照。 從那里,我將使用地圖圖像做進一步的工作。 但是現在,我只是將快照作為結果數據返回,因此我可以看到它們代表地圖的程度。

- (void)loadTileAtPath:(MKTileOverlayPath)path
                result:(void (^)(NSData *data, NSError *error))result
{
    double divisions = pow(2, (float)path.z);

    MKMapSize tileSize = MKMapSizeMake(MKMapSizeWorld.width / divisions, MKMapSizeWorld.height / divisions);

    MKMapPoint tilePoint = MKMapPointMake(path.x * tileSize.width, path.y * tileSize.height);

    MKMapRect tileRect = MKMapRectMake(tilePoint.x, tilePoint.y, tileSize.width, tileSize.height);
    MKMapSnapshotOptions *options = [[MKMapSnapshotOptions alloc] init];
    options.mapRect = tileRect;
    options.size = CGSizeMake(tileSize.width, tileSize.height);
    options.showsBuildings = NO;
    options.showsPointsOfInterest = NO;
    options.mapType = MKMapTypeStandard;
    MKMapSnapshotter *snapshotter = [[MKMapSnapshotter alloc] initWithOptions:options];
    [snapshotter startWithCompletionHandler:^(MKMapSnapshot *snapshot, NSError *error) {
        result(UIImagePNGRepresentation(snapshot.image), nil);
    }];
}

鑒於這里的數學都是正確的,理論上它應該顯示一張完美的地圖。 相反,它顯示:

在此處輸入圖片說明

這就是它應該是什么樣子(下面的地圖是什么樣子的):

在此處輸入圖片說明

“Bad MKMapSnapshotOptions”消息可能是由於選項的size不正確。 尺寸不能太大(看起來5000px還可以,但是1000px太大了)。 尺寸也不能有子像素尺寸,所以 123.4px 是無效的。 確保在生成尺寸時使用round()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM