julienG
julienG

Reputation: 21

MKTileoverlay issue in swift

I'm quite new to iOS development and am facing an issue using MapKit.

I am trying to create a simple application to overlay a raster image to a map created with mapkit.

Here is the code for my tabViewcontroller:

import UIKit
import MapKit

class J_1_TabViewController: UIViewController,MKMapViewDelegate {

@IBOutlet weak var CarteMapView: MKMapView!

override func viewDidLoad() {
    super.viewDidLoad()


    // Localisation centre de Clermont-Ferrand pour centrer la carte
    let location = CLLocationCoordinate2D(
        latitude: 45.774792,
        longitude: 3.091641
    )


    let span = MKCoordinateSpanMake(0.1, 0.1)  // declaration du niveau d'affichage en X et Y en °
    let region = MKCoordinateRegion(center: location, span: span) //declaration de la zone de la carte


    self.CarteMapView.setRegion(region, animated: true)



    //var template = "http://tile.openstreetmap.org/{z}/{x}/{y}.png"  //declaration de l'adresse pour les tuiles


    var template = "http://81.255.152.141/galineau/carteNO2/{z}/{x}/{y}.png"

    let carte_indice = MKTileOverlay(URLTemplate:template)

    self.CarteMapView.addOverlay(carte_indice)


}

And the code for my rendererForOverlay

func mapView(mapView: MKMapView!, rendererForOverlay overlay: MKOverlay!) -> MKOverlayRenderer! {
    if overlay is MKTileOverlay {
        var carte_Renderer = MKTileOverlayRenderer(overlay: overlay)
        carte_Renderer.alpha = 0.9
        return carte_Renderer
    }

    return nil
}

In my example, if I am using OpenStreetMap link, my overlay is ok but if I am using my own tiles, It is not working anymore. I have generated my tiles using gdal and when I try to visualize them on safari, it seems ok. Here is the link to visualize my tiles: MyMap

I can't understand why they are not showing in my app?

Upvotes: 2

Views: 1512

Answers (1)

Daniel Mavrakis
Daniel Mavrakis

Reputation: 592

If you are running iOS9, you may have an issue with App Transport Security as your tiles are accessed through an unsecure http link, and Apple policy now prohibits access to arbitrary http content.

See detailed guidelines under NSAppSecurity at https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html

You should explicitely add your domain in Exception Domains in your Info.plist. In the meantime, for testing purposes only, it is possible to disable App Transport Security in inserting below key in Info.plist

<key>NSAppTransportSecurity</key>  
     <dict>  
          <key>NSAllowsArbitraryLoads</key><true/>  
     </dict>  

The above is only for testing, for any commercial application you should list the unsecure domains accessed through http in Exception Domains.

A good summary on ATS could be found here http://ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11/

Upvotes: 2

Related Questions