4

在执行期间,图像在整个地图中重复。我还可以指定一个 UIImage 来代替 URLTemplate?

我在某个特定位置添加了叠加图像。正好在当前位置。

谢谢

这是我的代码:

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
    }

}
4

2 回答 2

1

我认为模板网址必须是:

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

问候。

于 2015-08-05T12:20:04.853 回答
-1

不太明白你想用这些瓷砖实现什么。

虽然,您可以通过以下方式获取本地资源的 NSURL:

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

或者,如果您需要为不同的 X/Y/Z/比例动态提供图块,您可以子类化 MKTileOverlay 并覆盖loadTileAtPath方法。

于 2015-08-05T12:22:38.067 回答