在我的 iOS 应用程序中,我打算使用以下代码获取我的 Google map map 的快照:
UIGraphicsBeginImageContext(self.mapView.frame.size)
if let context = UIGraphicsGetCurrentContext() {
self.mapView.layer.render(in: context)
}
self.imageSnapshot = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
但是,返回的图像是黑屏图像,左下角带有 Google Logo 。我该怎么做才能获得正确的 map 图像快照?
最佳答案
假设 mapView
是 GMSMapView
的一个实例,下面的代码应该可以工作
let image = UIGraphicsImageRenderer(size: mapView.bounds.size).image { _ in
mapView.drawHierarchy(in: mapView.bounds, afterScreenUpdates: true)
}
当然,这是假设在调用此代码之前 map 已实际呈现。
关于ios - 如何在 iOS 中获取谷歌地图的快照,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61263395/