8

mapView のスクリーンショットを撮り、ポリラインを含める方法はありますか? MKSnapShotter が返す画像に CGPoint を描画する必要があると思いますが、その方法がわかりません。

現在のコード

      func takeSnapshot(mapView: MKMapView, withCallback: (UIImage?, NSError?) -> ()) {
    let options = MKMapSnapshotOptions()
    options.region = mapView.region
    options.size = mapView.frame.size
    options.scale = UIScreen.main().scale

    let snapshotter = MKMapSnapshotter(options: options)


    snapshotter.start() { snapshot, error in
        guard snapshot != nil else {
            withCallback(nil, error)
            return
        }

        if let image = snapshot?.image{



            withCallback(image, nil)

            for coordinate in self.area {

                image.draw(at:snapshot!.point(for: coordinate))

            }

        }

    }
}
4

3 に答える 3

0

MKMapView でユーザーに表示される画像のコピーだけが必要な場合は、それが UIView サブクラスであることを覚えておいてください。したがって、これを行うことができます...

public extension UIView {
    public var snapshot: UIImage? {
        get {
            UIGraphicsBeginImageContextWithOptions(self.bounds.size, false, UIScreen.main.scale)
            self.drawHierarchy(in: self.bounds, afterScreenUpdates: true)
            let image = UIGraphicsGetImageFromCurrentImageContext()
            UIGraphicsEndImageContext()
            return image
        }
    }
}

// ...
if let img = self.mapView.snapshot {
    // Do something
}
于 2018-09-12T14:51:22.170 に答える