ios - 如何在 iOS 中获取谷歌地图的快照

标签 ios swift google-maps screenshot google-maps-sdk-ios

在我的 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 图像快照?

最佳答案

假设 mapViewGMSMapView 的一个实例,下面的代码应该可以工作

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/

相关文章:

ios - [UITableView indexPathsForVisibleRows] 可能存在错误?

html - 为什么 iOS Safari 用户代理样式表似乎覆盖了正文上的边距样式?

iphone - 在自定义 UIBarButtonItem 周围设置边框

ios - 如何更改搜索栏的高度? swift

swift - '子字符串(到 : )' is deprecated: Please use String slicing subscript with a ' partial range upto' operator

ios - 弹出一个导航 Controller

ios - 在 xcode 7.3 : could not build Objective-C module 'libxml2' 上运行测试

android - Google map 没有空图 block 、没有 map 、没有 LogCat 错误。 map API V2 6/2013

javascript - 使用 Google places API 仅自动完成地名

google-maps - 如何去除谷歌地图自动完成下拉列表中的 "Powered by Google"标识?