Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace MKMapView with static image

Is it possible to display a static image instead of the default MapView, where the current location is always the center of the image?

I want to display an image where the center is current position and add pins on it depending on coordinates (distance and direction). I want to calculate distance between too and maybe rotate the image/pins depending on which direction the phone is pointing.

I thought it might be easiest to do with a MKMapView and replace it with a static image, as I can use all the build-in functionality, but right now it seems impossible to change the map to a static image?

I could also just paint directly on an image, but how would that work, and should I do that? I guess it would be something with polar coordinates.

like image 510
Emil Moe Avatar asked Jan 27 '26 18:01

Emil Moe


1 Answers

With iOS7, you have MKMapSnapshotter which can render a snapshot of a map region in a background thread. You can then take an image of that snapshot.

MKMapSnapshotOptions* options = [MKMapSnapshotOptions new];
//Setup options here:
options.camera = ...
options.region = ...

MKMapSnapshotter* snapshotter = [[MKMapSnapshotter alloc] initWithOptions:options];
[snapshotter startWithQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) completionHandler:^(MKMapSnapshot* snapshot, NSError* error) {

    // get the image associated with the snapshot

    UIImage *image = snapshot.image;

    dispatch_async(dispatch_get_main_queue(), ^ {
        //Make sure to access UIKit UI elements on the main thread!
        [self.imageView setImage: image];
    });
}
like image 159
Léo Natan Avatar answered Jan 29 '26 07:01

Léo Natan