I've made a viewController that is showing a third party map as an overlay to the standard apple map(MapKit). This did work earlier, but now I'm getting some errors that I don't understand. I hope you are able to help.
Seems like there is some issue with a database file...
2017-11-09 00:10:04.397439+0100 Shoota[13022:4546380] [GEODBWriter] /BuildRoot/Library/Caches/com.apple.xbs/Sources/GeoServices/GeoServices- 1357.31.9.8.2/GEODBWriter.mm:601 Could not open database (/var/mobile/Library/Caches/com.apple.geod/MapTiles/MapTiles.sqlitedb): (14) unable to open database file
2017-11-09 00:10:04.398077+0100 Shoota[13022:4546380] [GEODBWriter] /BuildRoot/Library/Caches/com.apple.xbs/Sources/GeoServices/GeoServices-1357.31.9.8.2/GEODBWriter.mm:601 Could not open database (/var/mobile/Library/Caches/com.apple.geod/MapTiles/MapTiles.sqlitedb): (14) unable to open database file
2017-11-09 00:10:04.412848+0100 Shoota[13022:4546380] [logging] API called with NULL prepared statement
2017-11-09 00:10:04.413219+0100 Shoota[13022:4546380] [logging] misuse at line 84067 of [2b0954060f]
2017-11-09 00:10:04.413228+0100 Shoota[13022:4546380] [logging] API called with NULL prepared statement
2017-11-09 00:10:04.413232+0100 Shoota[13022:4546380] [logging] misuse at line 84067 of [2b0954060f]
2017-11-09 00:10:04.413256+0100 Shoota[13022:4546380] [GEODBWriter] /BuildRoot/Library/Caches/com.apple.xbs/Sources/GeoServices/GeoServices-1357.31.9.8.2/GEODBWriter.mm:437 SQL error: (21) out of memory
2017-11-09 00:10:04.435568+0100 Shoota[13022:4546267] [VKDefault] Tile 34210.17884.16 (128) in current unloaded state for 0.01 seconds - Raster Overlays Above Labels - Failed to decode (terminal) (0.01 sec)
2017-11-09 00:10:04.435602+0100 Shoota[13022:4546267] [VKDefault] Tile 34208.17884.16 (128) in current unloaded state for 0.01 seconds - Raster Overlays Above Labels - Failed to decode (terminal) (0.01 sec)
The code below is the UIViewController that I use.
import UIKit
import MapKit
class recordVC: UIViewController, MKMapViewDelegate {
@IBOutlet weak var mapView: MKMapView!
var tileRenderer: MKTileOverlayRenderer!
// set initial location in Aspøya
let initialLocation = CLLocation(latitude: 63.011018, longitude: 7.914721)
// Set the zoom level of the location
let regionRadius: CLLocationDistance = 1000
func centerMapOnLocation(location: CLLocation) {
let coordinateRegion = MKCoordinateRegionMakeWithDistance(location.coordinate, regionRadius, regionRadius)
mapView.setRegion(coordinateRegion, animated: true)
}
func setupTileRenderer() {
let template = "https://opencache.statkart.no/gatekeeper/gk/gk.open_gmaps?layers=norgeskart_bakgrunn&zoom={z}&x={x}&y={y}&format=image/jpeg"
let overlay = MKTileOverlay(urlTemplate: template)
overlay.canReplaceMapContent = true
mapView.add(overlay, level: .aboveLabels)
tileRenderer = MKTileOverlayRenderer(tileOverlay: overlay)
}
override func viewWillAppear(_ animated: Bool) {
}
override func viewDidLoad() {
super.viewDidLoad()
// hide the tab bar
// Runs the function to get overlay tiles when page is reloaded
setupTileRenderer()
// Sets the map settings
mapView.showsUserLocation = true
mapView.showsCompass = true
mapView.setUserTrackingMode(.followWithHeading, animated: true)
mapView.delegate = self
mapView.isZoomEnabled = true
mapView.isRotateEnabled = true
// Center the map on a defined location
centerMapOnLocation(location: initialLocation)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
return tileRenderer
}
}