我有以下代碼,但它沒有顯示位置。Swift Map工具包註釋
import Foundation
import UIKit
import MapKit
import CoreLocation
class ViewTwo : UIViewController {
@IBOutlet var Map: MKMapView!
override func didReceiveMemoryWarning() {
super.viewDidLoad()
var location = CLLocationCoordinate2DMake(51.385493, 6.741528)
var span = MKCoordinateSpanMake(0.2, 0.2)
var region = MKCoordinateRegion(center: location , span: span)
Map.setRegion(region, animated: true)
var annotation = MKPointAnnotation()
annotation.coordinate = location
annotation.title = "hi"
annotation.coordinate = location
Map.addAnnotation(annotation)
}
感謝您的幫助提前。
您正在使用didReceiveMemoryWarning()中的代碼。呦應該在viewDidLoad()函數中編寫代碼。 – emresancaktar