Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iOS中获取谷歌地图的快照_Ios_Swift_Google Maps_Screenshot_Google Maps Sdk Ios - Fatal编程技术网

如何在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

在我的iOS应用程序中,我打算使用以下代码获取我的谷歌地图快照:

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)
}
当然,这是假设贴图在调用此代码之前已实际渲染