在执行期间,图像在整个地图中重复。我还可以指定一个 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
}
}