Görüntünün ortasında bir açıklama ekleyen bir yöntem (tamamlama bloğuyla) sağlayarak @DevC yanıtına eklemek istiyorum. İlk başta, anlık görüntü başlamadan önce ek açıklama ekleyip eklemediğimi görmek istedim, ancak MKMapSnapshotter
not support this. Bu yüzden, bulduğum çözüm, bir iğne oluşturmak, harita görüntüsünün üstüne çizmek ve daha sonra haritanın + iğnesinin başka bir görüntüsünü oluşturmaktır. Ben harita görüntüsüne ek açıklamaları eklemek isteyen insanlara bu bazı kullanım umut
typedef void(^map_screenshot_completion)(UIImage *);
: Bu yöntem aynı zamanda şöyle beyan edilecek bir tamamlanma başlığı gerektirir
-(void)create_map_screenshot:(MKCoordinateRegion)region :(map_screenshot_completion)map_block {
// Set the map snapshot properties.
MKMapSnapshotOptions *snap_options = [[MKMapSnapshotOptions alloc] init];
snap_options.region = region;
snap_options.size = // Set the frame size e.g.: custom_view.frame.size;
snap_options.scale = [[UIScreen mainScreen] scale];
// Initialise the map snapshot camera.
MKMapSnapshotter *map_camera = [[MKMapSnapshotter alloc] initWithOptions:snap_options];
// Take a picture of the map.
[map_camera startWithCompletionHandler:^(MKMapSnapshot *snapshot, NSError *error) {
// Check if the map image was created.
if ((error == nil) && (snapshot.image != nil)) {
// Create the pin image view.
MKAnnotationView *pin = [[MKPinAnnotationView alloc] initWithAnnotation:nil reuseIdentifier:nil];
// Get the map image data.
UIImage *image = snapshot.image;
// Create a map + location pin image.
UIGraphicsBeginImageContextWithOptions(image.size, YES, image.scale); {
[image drawAtPoint:CGPointMake(0.0f, 0.0f)];
CGRect rect = CGRectMake(0.0f, 0.0f, image.size.width, image.size.height);
// Create the pin co-ordinate point.
CGPoint point = [snapshot pointForCoordinate:region.center];
if (CGRectContainsPoint(rect, point)) {
// Draw the pin in the middle of the map.
point.x = (point.x + pin.centerOffset.x - (pin.bounds.size.width/2.0f));
point.y = (point.y + pin.centerOffset.y - (pin.bounds.size.height/2.0f));
[pin.image drawAtPoint:point];
}
}
// Get the new map + pin image.
UIImage *map_plus_pin = UIGraphicsGetImageFromCurrentImageContext();
// Return the new image data.
UIGraphicsEndImageContext();
map_block(map_plus_pin);
}
else {
map_block(nil);
}
}];
}
: İşte benim özel yöntemidir .
benim için çalışmasına teşekkürler ve zamanımı kurtar. –
pin image edit edebilirim –