Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 拍摄特定坐标的Mkmap快照_Ios_Objective C_Mkmapview_Snapshot - Fatal编程技术网

Ios 拍摄特定坐标的Mkmap快照

Ios 拍摄特定坐标的Mkmap快照,ios,objective-c,mkmapview,snapshot,Ios,Objective C,Mkmapview,Snapshot,如何拍摄特定坐标的地图快照?现在它拍摄了整个地图的快照,但我只想拍摄纽约的快照(北纬40.7127度,北纬74.0059度)。我试着把region.center改成纽约坐标,但我一直在旧金山 MKMapSnapshotOptions *options = [[MKMapSnapshotOptions alloc] init]; options.region = self.mapView.region; options.scale = [UIScreen mainScreen].scale; op

如何拍摄特定坐标的地图快照?现在它拍摄了整个地图的快照,但我只想拍摄纽约的快照(北纬40.7127度,北纬74.0059度)。我试着把region.center改成纽约坐标,但我一直在旧金山

MKMapSnapshotOptions *options = [[MKMapSnapshotOptions alloc] init];
options.region = self.mapView.region;
options.scale = [UIScreen mainScreen].scale;
options.size = self.mapView.frame.size;

MKMapSnapshotter *snapshotter = [[MKMapSnapshotter alloc] initWithOptions:options];
[snapshotter startWithCompletionHandler:^(MKMapSnapshot *snapshot, NSError *error) {
UIImage *image = snapshot.image;
NSData *data = UIImagePNGRepresentation(image);
[data writeToFile:[self snapshotFilename] atomically:YES];
}];

我以前做过。这里有一个拍摄快照的方法。方法所需的
CLLocationCoordinate2D
参数,在您的情况下,该参数是位置坐标

CLLocationCoordinate2D centerPoint = CLLocationCoordinate2DMake(40.730872, -74.003066);
在下面的方法中传递此坐标,它将捕捉指定位置的快照。如果需要,可以从此方法中删除动画,这与功能无关,但最好将动画贴图显示到特定位置。看看这个,分享你的想法

- (void) takeSnapShot:(CLLocationCoordinate2D)centerPoint {

    __block MKCoordinateRegion newRegion = self.mapView.region;

    // Animation is use to animate map to location specified in parameter. If not required remove it.
    [UIView animateWithDuration:1.5 animations:^{

        MKCoordinateRegion region;
        region.center.latitude = centerPoint.latitude;
        region.center.longitude = centerPoint.longitude;
        region.span.latitudeDelta = 0.15f;
        region.span.longitudeDelta = 0.15f;
        newRegion = region;

        [self.mapView setRegion:region animated:YES];

    } completion:^(BOOL finished) {

        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString *fileName = [documentsDirectory stringByAppendingPathComponent:@"Snap.png"];

        MKMapSnapshotOptions *options = [[MKMapSnapshotOptions alloc] init];
        options.region = newRegion;
        options.scale = [UIScreen mainScreen].scale;
        options.size = self.mapView.frame.size;

        MKMapSnapshotter *snapshotter = [[MKMapSnapshotter alloc] initWithOptions:options];
        [snapshotter startWithCompletionHandler:^(MKMapSnapshot *snapshot, NSError *error) {
            UIImage *image = snapshot.image;
            NSData *data = UIImagePNGRepresentation(image);
            [data writeToFile:fileName atomically:YES];
        }];

    }];
}