実行中、画像はマップ全体で繰り返されます。URLTemplate の代わりに UIImage を指定することもできますか?
特定の場所にオーバーレイ画像を追加しました。正確には現在位置。
ありがとうございました
これは私のコードです:
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
}
}