gpt4 book ai didi

ios - 如何使用 MapBox 读取离线 map

转载 作者:行者123 更新时间:2023-11-28 05:50:41 25 4
gpt4 key购买 nike

当我尝试在我的 iOS 应用程序中加载离线 mapbox map 时遇到问题。在下面的文档中,他们没有解释如何在下载后加载 map 。 https://www.mapbox.com/ios-sdk/maps/examples/offline-pack/

现在,为了加载离线 map ,我添加了这段代码,将 cache.db 文件从临时缓存复制到有效路径,如此链接中所述 https://github.com/mapbox/mapbox-gl-native/wiki/Sideloading-offline-maps

let sourceURL = NSURL(fileURLWithPath:"\(NSHomeDirectory())/Library/Application Support/*****************/.mapbox/cache.db")
let TemporaryPathURL = NSURL(fileURLWithPath: "\(NSHomeDirectory())/Documents/***********")
let databaseURL = TemporaryPathURL.appendingPathComponent("cache.db")
if !(FileManager.default.fileExists(atPath: (databaseURL?.absoluteString)!)) {
do {
try? FileManager.default.copyItem(at: sourceURL as URL, to: databaseURL!)
} catch {
print ("ERROR: Fichier existant !!!!")
}
}

但是我没有离线获取 map 区域!!!!请帮忙

最好的问候。

最佳答案

嘿,如果你已经下载了区域(使用链接 https://www.mapbox.com/ios-sdk/maps/examples/offline-pack/ ),那么你可以试试这个代码来加载 map

///加载离线 map

func loadOffline(){

//if app is offline load tiles
if (MGLOfflineStorage.shared.packs?.count ?? 0) > 0{
var index = Int()
for i in 0..<(MGLOfflineStorage.shared.packs?.count ?? 0){
let dict = NSKeyedUnarchiver.unarchiveObject(with: MGLOfflineStorage.shared.packs?[i].context ?? Data()) as! [String: Any]
if (Region_Name) == JSON(dict["name"] ?? "").stringValue{
index = i
break
}
}

mapView.styleURL = MGLOfflineStorage.shared.packs?[index].region.styleURL
if let tiles = MGLOfflineStorage.shared.packs?[index].region as? MGLTilePyramidOfflineRegion{

mapView.setVisibleCoordinateBounds(tiles.bounds, animated: true)
guard ((self.model.data?.count ?? 0) != 0) || ((self.model.mapData?.regionName ?? "") == "") else{
return
}
self.mapView.zoomLevel = tiles.maximumXoomLevel
self.mapView.centerCoordinate = CLLocationCoordinate2D(latitude: JSON(self.model.data?[0].latitude ?? "").doubleValue, longitude: JSON(self.model.data?[0].longitude ?? "").doubleValue)

}
}
}

关于ios - 如何使用 MapBox 读取离线 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53069026/

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