mec*_*don 4 google-maps screenshot ios google-maps-sdk-ios swift
在我的 iOS 应用程序中,我打算使用以下代码获取我的 Google 地图地图的快照:
UIGraphicsBeginImageContext(self.mapView.frame.size)
if let context = UIGraphicsGetCurrentContext() {
self.mapView.layer.render(in: context)
}
self.imageSnapshot = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
Run Code Online (Sandbox Code Playgroud)
但是,返回的图像是黑屏图像,左下角有 Google 徽标。我该怎么做才能获得正确的地图图像快照?
假设mapView是 的一个实例GMSMapView,以下内容应该有效
let image = UIGraphicsImageRenderer(size: mapView.bounds.size).image { _ in
mapView.drawHierarchy(in: mapView.bounds, afterScreenUpdates: true)
}
Run Code Online (Sandbox Code Playgroud)
当然,这是假设在调用此代码之前地图已实际渲染。
| 归档时间: |
|
| 查看次数: |
1376 次 |
| 最近记录: |