How to display MKSnapshot in Swift (iOS) -


i trying take snapshot of street view of location pinned in app using mksnapshotter. have code:

var options: mkmapsnapshotoptions = mkmapsnapshotoptions();     options.region = self.attractiondetailmap.region;     options.size = self.attractiondetailmap.frame.size;     options.scale = uiscreen.mainscreen().scale;      var fileurl:nsurl = nsurl(fileurlwithpath: "path/to/snapshot.png")!;     var snapshotter:mkmapsnapshotter = mkmapsnapshotter();     snapshotter.startwithcompletionhandler { (snapshot:mkmapsnapshot!, error:nserror!) -> void in         if(error != nil) {             println("error: " + error.localizeddescription);             return;         }         let image:uiimage = snapshot.image;         var data:nsdata = uiimagepngrepresentation(image);         data.writetourl(fileurl, atomically: true);          var pin:mkannotationview = mkannotationview();         uigraphicsbeginimagecontextwithoptions(image.size, true, image.scale);         image.drawatpoint(cgpointmake(0.0, 0.0));         var rect:cgrect = cgrectmake(0.0, 0.0, image.size.width, image.size.height);         annotation in self.attractiondetailmap.annotations as! [mkannotation]{             var point:cgpoint = snapshot.pointforcoordinate(annotation.coordinate);             if(cgrectcontainspoint(rect, point)) {                 point.x = point.x + pin.centeroffset.x - (pin.bounds.size.width / 2.0);                 point.y = point.y + pin.centeroffset.y - (pin.bounds.size.height / 2.0);                 pin.image.drawatpoint(point);             }         }          var compositeimage:uiimage = uigraphicsgetimagefromcurrentimagecontext();         var data2:nsdata = uiimagepngrepresentation(compositeimage);         data.writetourl(fileurl, atomically: true);         uigraphicsendimagecontext(); 

now have image, don't know how display snapshot mapview.

any appreciated!

so mkmapsnapshotter class isn't used display inside of mapview. returns image of map isn't compatible mapview. have used when need performance displaying map pin in tableview cell or collectionview. performs way better displaying actual mapview inside of tableview.

so once have snapshot load in uiimageview. looks mapview would.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -