4

During the execute the image is repeated throughout map. I could also specify a UIImage in place of URLTemplate?

I have add an overlay image in some particular location. Precisely at the current position.

Thank you

This is my 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.Satellite

        //Map centre
        let centre = CLLocationCoordinate2D(latitude: 40.8325769,
            longitude: 14.318884400000002)

        //Declare span of map
        let span = MKCoordinateSpan(latitudeDelta: 0.05,
            longitudeDelta: 0.05)

        //Set region of the map
        let region = MKCoordinateRegion(center: centre, span: span)
        self.mapView.setRegion(region, animated: false)
        self.mapView.regionThatFits(region)



        var template = "http://tile.openstreetmap.org/0/0/0.png"

        let carte_indice = MKTileOverlay(URLTemplate:template)


        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!
    {

            if overlay is MKTileOverlay
            {
                var renderer = MKTileOverlayRenderer(overlay:overlay)

                renderer.alpha = 0.8

                return renderer
            }
            return nil
    }

}
vinbhai4u
  • 1,329
  • 3
  • 19
  • 36
Michele Mola
  • 101
  • 2
  • 7

2 Answers2

1

I think the template url must be:

var template = "http://tile.openstreetmap.org/{z}/{x}/{y}.png"

regards.

onix
  • 84
  • 4
-1

Don't quite understand what you're trying to achieve with that tiles.

Although, you can get the NSURL for a local resource by:

if let tileUrl = NSBundle.mainBundle().URLForResource(ZZZ, withExtension: XXX, subdirectory: YYY)

or if you would need to dynamically provide tiles for different X/Y/Z/scale, you can subclass MKTileOverlay and override loadTileAtPath method.

rshev
  • 4,086
  • 1
  • 23
  • 32