[英]renderMapImageInBoundingBox doesn't do anything on iOS
我有一個UITableView,其中每個單元格應該顯示一個地圖。 由於在一個視圖中有多個獨立的SKMapView實例是已知的限制(請參閱http://developer.skobbler.com/getting-started/ios#sec29 ),而且我也不希望每個單元格中都有一個SKMapView(性能)我以為我會使用renderMapImageInBoundingBox並創建要在tableCells中顯示的地圖圖像。
我已經嘗試了幾件事,並刪除了代碼,只為第一張地圖渲染圖像。 這是我在UITableViewController的viewDidAppear中的精簡版本(我也嘗試過viewDidLoad,但什么也沒有)。
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(true)
//Initialize, set delegate, and customize map appearance
var mapView = SKMapView(frame: CGRectMake(0, 0, 963, 200))
mapView.delegate = self
mapView.applySettingsFromFileAtPath(JSONFilePath)
mapView.mapScaleView.hidden = true
mapView.settings.showAccuracyCircle = false
mapView.settings.panningEnabled = false
mapView.settings.rotationEnabled = false
mapView.settings.showStreetBadges = false
mapView.settings.showHouseNumbers = false
mapView.settings.showMapPoiIcons = false
mapView.settings.showOneWays = false
//Draw a track on the map
let track = tracks[0]
var polyline = SKPolyline()
polyline.coordinates = track.points
polyline.fillColor = themeTintColor
polyline.lineWidth = 3
polyline.backgroundLineWidth = 4
polyline.borderDotsSize = 1
polyline.borderDotsSpacingSize = 5
mapView.addPolyline(polyline)
//Set BoundingBox
let boundingBox = SKBoundingBox(topLeftCoordinate: CLLocationCoordinate2DMake(track.ne.coordinate.latitude, track.sw.coordinate.longitude), bottomRightCoordinate: CLLocationCoordinate2DMake(track.sw.coordinate.latitude, track.ne.coordinate.longitude))
// Add the mapView to the view just to see if it displays correctly. (It does!)
mapView.fitBounds(boundingBox, withPadding: CGSizeMake(20, 20))
self.view.addSubview(mapView)
// Actual PNG rendering
let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String
mapView.renderMapImageInBoundingBox(boundingBox, toPath: documentsPath, withSize: CGSizeMake(1000, 220))
println("Rendering in progress")
}
func mapViewDidFinishRenderingImageInBoundingBox(mapView: SKMapView!) {
println("ImageRenderingFinished")
}
mapView正確顯示(帶有正確的邊界框),並且在日志中看到“正在渲染”消息,但是沒有調用mapViewDidFinishRenderingImageInBoundingBox,並且在我的應用容器中看不到png文件。 沒有編譯器或運行時錯誤。 (順便說一句,我沒有忘記添加SKMapViewDelegate)
有人知道我在做什么錯嗎? 還是我遇到了錯誤? 使用Xcode 6.1,在Swift中為iOS8開發。
為此事道歉。 我犯了一個非常非常愚蠢的錯誤。 我給documentsPath作為函數的參數,該函數是一個目錄,但是函數需要完整的路徑,包括文件名。
這使其工作:
let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String
let imagePath = documentsPath.stringByAppendingPathComponent("images/mapImage.png")
mapView.renderMapImageInBoundingBox(boundingBox, toPath: imagePath, withSize: CGSizeMake(1000, 220))
我應該多喝咖啡!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.