High resolution screen shot from map

107 views Asked by At

I want screen shot from specific location of my Mapview. and i have used following code. its worked properly but screen shot is little bit blur. i want high resolution of Screen shot. please check my code. Thanks.!

func takeSnapShotForSaveSearch(_ centerPoint: CLLocationCoordinate2D) {

    var newRegion = mapHomes.region

    UIView.animate(withDuration: 0.0, animations: {() -> Void in

        let region = MKCoordinateRegionMakeWithDistance(centerPoint, 500.0, 500.0)
        //  region.center = centerPoint
        //  region.span.latitudeDelta = 1.0
        //  region.span.longitudeDelta = 1.0

        newRegion = region

    }, completion: {(_ finished: Bool) -> Void in

        var paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
        let documentsDirectory = paths[0]

        let fileName = URL(fileURLWithPath: documentsDirectory).appendingPathComponent("SaveSearch.png").absoluteString

        let options = MKMapSnapshotOptions()
        options.region = newRegion
        options.showsBuildings = false
        options.showsPointsOfInterest = false
        options.size = CGSize(width: 250.0, height: 250.0)

        let snapshotter = MKMapSnapshotter(options: options)
        snapshotter.start(completionHandler: { (snapShot, error) in

            let image = snapShot?.image

            if image != nil {
                let data = UIImagePNGRepresentation(image!)

                let fileURL = URL(string: fileName)

                do {
                    try data?.write(to: fileURL!)
                } catch {
                    print(error)
                }
            }
        })
    })
}
0

There are 0 answers