如何在iOS中获取谷歌地图的快照
在我的iOS应用程序中,我打算使用以下代码获取我的谷歌地图快照:如何在iOS中获取谷歌地图的快照,ios,swift,google-maps,screenshot,google-maps-sdk-ios,Ios,Swift,Google Maps,Screenshot,Google Maps Sdk Ios,在我的iOS应用程序中,我打算使用以下代码获取我的谷歌地图快照: UIGraphicsBeginImageContext(self.mapView.frame.size) if let context = UIGraphicsGetCurrentContext() { self.mapView.layer.render(in: context) } self.imageSnapshot = UIGraphicsGetImageFromCurrentImageContext() UIGra
UIGraphicsBeginImageContext(self.mapView.frame.size)
if let context = UIGraphicsGetCurrentContext() {
self.mapView.layer.render(in: context)
}
self.imageSnapshot = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
但是,返回的图像是一张黑屏图像,左下角有谷歌标志。如何获得地图的正确图像快照?假设
mapView
是GMSMapView
的一个实例,下面的操作应该有效
let image = UIGraphicsImageRenderer(size: mapView.bounds.size).image { _ in
mapView.drawHierarchy(in: mapView.bounds, afterScreenUpdates: true)
}
当然,这是假设贴图在调用此代码之前已实际渲染