gpt4 book ai didi

Swift Google map - 加载区域设置图 block

转载 作者:行者123 更新时间:2023-11-30 11:00:53 24 4
gpt4 key购买 nike

我正在使用 Swift 和 Google map ,并在我的文档目录中保存了一些用于叠加在 Zoom/lat/lng.png 结构中的图 block (例如 file:///....documents/3/2/3. .png)

 let urls: GMSTileURLConstructor = {(x, y, zoom) in
let url = "\(documentsUrl)\(zoom)/\(x)/\(y).png"
return URL(string: url)
}
layer = GMSURLTileLayer(urlConstructor: urls)
...

该代码片段适用于在线层,没有任何问题。但是当 filesUrl 是我的本地目录时,我收到

Task .<1> load failed with error Error Domain=NSURLErrorDomain Code=-1100 "The requested URL was not found on this server." UserInfo={NSLocalizedDescription=The requested URL was not found on this server., NSErrorFailingURLStringKey=file:///.........../Documents/7/65/42.png

是否有机会使用 Swift + Google map 获得离线图 block ?

非常感谢卡尔斯蒂

最佳答案

只需使用您自己的类并覆盖tileFor-function

class OfflineTileLayer: GMSSyncTileLayer {
override func tileFor(x: UInt, y: UInt, zoom: UInt) -> UIImage? {

let documentsUrl = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!

let reqPath = URL(string: "\(documentsUrl)\(zoom)/\(x)/\(y).png")!.path
print (reqPath)
if FileManager.default.fileExists(atPath: reqPath) {
print ("> IS ACTIVE!")
let url = NSURL(string: reqPath)
let data = NSData(contentsOf: url! as URL)
return UIImage(data: data! as Data)
}

return kGMSTileLayerNoTile
}
}

并从 map 初始化函数中调用它

 offlineLayer = OfflineTileLayer()
offlineLayer.map = yourGoogleMap

关于Swift Google map - 加载区域设置图 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53381845/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com