【问题标题】:How to obtain a snapshot of Google Maps in iOS如何在 iOS 中获取谷歌地图的快照
【发布时间】:2020-04-17 02:56:07
【问题描述】:

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

UIGraphicsBeginImageContext(self.mapView.frame.size)
if let context = UIGraphicsGetCurrentContext() {
    self.mapView.layer.render(in: context)
}
self.imageSnapshot = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

但是,返回的图像是左下角带有 Google 徽标的黑屏图像。我该怎么做才能获得正确的地图图像快照?

【问题讨论】:

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


    【解决方案1】:

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

    let image = UIGraphicsImageRenderer(size: mapView.bounds.size).image { _ in
        mapView.drawHierarchy(in: mapView.bounds, afterScreenUpdates: true)
    }
    

    这是假设地图在调用此代码之前已经实际渲染。

    【讨论】:

      猜你喜欢
      • 2016-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-06
      相关资源
      最近更新 更多