通过整理MKMapview屏幕截图构建一个完整的世界地图



我正试图在MkMapView上用一组覆盖的引脚构建一幅整个世界的图片。为了做到这一点,我尝试我的算法如下:截屏将MkMapRegion设置为当前不在屏幕上的地图的下一部分将所有截图整理成一张大图。

我有一个问题,因为当我改变纬度时,MkMapView不能准确地将地图居中在所需的点上,我设置的纬度和我最终得到的纬度是不同的(并且根据相关的经度而变化。对于经度来说,这很好。我似乎能够将地图集中在我想要的点上。底线是,我似乎无法准确地重新创建整个世界的地图,因为我最终得到了太多或太少的垂直截图。

有人有什么建议吗?

此处的代码片段:

   dispatch_queue_t _queue2 = dispatch_queue_create("com.screenShots", DISPATCH_QUEUE_SERIAL);
dispatch_async(_queue2, ^{
    int maxLatitudeScreens,maxLongitudeScreens;

    if (UIUserInterfaceIdiomPad==UI_USER_INTERFACE_IDIOM()){
         maxLatitudeScreens=SCREENS_LATITUDE_IPAD;
        maxLongitudeScreens=SCREENS_LONGITUDE_IPAD;
    }else{
        maxLatitudeScreens=SCREENS_LATITUDE_IPHONE;
        maxLongitudeScreens=SCREENS_LONGITUDE_IPHONE;
    }
     @synchronized(self){
    for (int j=0; j<maxLongitudeScreens;j++){
        for (int i=0 ; i<maxLatitudeScreens; i++) {
            double latitudeDelta=45;
            double longitudeDelta=180;
            double latit=55.0-j*111.0;
            double longit=-180.0+i*longitudeDelta*2/maxLatitudeScreens;
            CLLocationCoordinate2D newCenter= CLLocationCoordinate2DMake(latit, longit);
            MKCoordinateSpan theSpan= MKCoordinateSpanMake(latitudeDelta, longitudeDelta);
            MKCoordinateRegion theRegion=MKCoordinateRegionMake(newCenter, theSpan);
            [_contactMapView setRegion:theRegion animated:YES];
            NSLog(@"latit=%f and longit=%f",_contactMapView.centerCoordinate.latitude, _contactMapView.centerCoordinate.longitude );
            NSLog(@"mapviewCenterlatitude=%f and longitude=%f",_contactMapView.centerCoordinate.latitude, _contactMapView.centerCoordinate.longitude );
             NSLog(@"latitudeSpan=%f and longitudeSpan=%f",_contactMapView.region.span.latitudeDelta, _contactMapView.region.span.longitudeDelta );
            sleep(3);
            [self screenshot:mapViewPrintFormatter.view];
            sleep(1);
        }
    }
    //UIImageWriteToSavedPhotosAlbum ([self collateImages],nil,nil,nil);
    [self   collateImages];
    [self shareCollatedMapViewImage];
}
});

您是否尝试在原始设置后将该区域排除在等式之外?只需使用setCenterCoordinate:animated:移动中心,缩放应保持一致。

相关内容

最新更新