Reputation: 69
Adding an overlay with a tiled map is supposed to be easy. I'm having a great problem. They don't show.
I have map tiles of the center of Bayeux in 15 16 and 17 zoom in a folder baymap. I slid the folder into the project.
here's the code
import UIKit
import MapKit
class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
@IBOutlet weak var mapView: MKMapView!
let locationManager = CLLocationManager()
var latitude: CLLocationDegrees = 0.0
var longitude: CLLocationDegrees = 0.0
var cnt: Int = 0
override func viewDidLoad() {
super.viewDidLoad()
self.mapView.delegate = self
self.mapView.mapType = MKMapType.Standard
//Map centre
let centre = CLLocationCoordinate2D(latitude: 49.275,
longitude: -0.7028)
//Declare span of map
let span = MKCoordinateSpan(latitudeDelta: 0.01,
longitudeDelta: 0.01)
//Set region of the map
let region = MKCoordinateRegion(center: centre, span: span)
self.mapView.setRegion(region, animated: false)
self.mapView.regionThatFits(region)
//Get the URL template to the map tiles
let baseURL = NSBundle.mainBundle().bundleURL.absoluteString
let urlTemplate = baseURL.stringByAppendingString("baymap/{z}/{x}/{y}.png/")
print(urlTemplate)
let carte_indice = MKTileOverlay(URLTemplate:urlTemplate)
carte_indice.geometryFlipped = true
carte_indice.canReplaceMapContent = false
self.mapView.addOverlay(carte_indice)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func mapView(mapView: MKMapView!, rendererForOverlay overlay: MKOverlay!) -> MKOverlayRenderer!
{
print("call overlay")
if overlay is MKTileOverlay
{
print("is MKTileoverlay")
var renderer = MKTileOverlayRenderer(overlay:overlay)
renderer.alpha = 0.8
return renderer
}
return nil
}
}
I've edited the question to add print "call overlay" and "is MKTileoverlay". They both print in the console.
The apple map of Bayeux shows up fine but no overlay.
In the console i'm getting dozens of errors like this which refer to tiles not in the bundle.
: Error loading URL file:///Users/colinmcgarry/Library/Developer/CoreSimulator/Devices/5A9A20A4-9C3F-4A65-8823-9721463FF985/data/Containers/Bundle/Application/D2C87A46-E848-4C0D-9B05-30E731EC037F/TileOverlaystack.app/baymap/17/65283/86214.png/: Error Domain=NSURLErrorDomain Code=-1100 "The requested URL was not found on this server."
can anyone see what I'm doing wrong. Is there a good tutorial some place for in bundle tile overlay in Swift?
thanks
Upvotes: 1
Views: 813
Reputation: 69
Found the solution. carte_indice.geometryFlipped = true
should be false.
depends on the tile system.
Upvotes: 0