MapKit Map - 注释不在模拟器上显示

时间:2016-09-28 08:48:20

标签: ios swift annotations apple-maps

我正在尝试在加载地图时在地图视图中显示标记,但地图会在地图视图中显示我的国家地图,但不会显示注释。我在做什么有什么不对吗?仅供参考我的模拟器位置设置为Apple。

import MapKit
import UIKit

class Capital: NSObject, MKAnnotation {
    var title: String?
    var coordinate: CLLocationCoordinate2D
    var info: String

    init(title: String, coordinate: CLLocationCoordinate2D, info: String) {
        self.title = title
        self.coordinate = coordinate
        self.info = info
    }
}





import MapKit
import UIKit

class ViewController: UIViewController, MKMapViewDelegate {
    @IBOutlet weak var mapView: MKMapView!

    override func viewDidLoad() {
        super.viewDidLoad()

        let london = Capital(title: "London", coordinate: CLLocationCoordinate2D(latitude: 51.507222, longitude: -0.1275), info: "Home to the 2012 Summer Olympics.")
        let oslo = Capital(title: "Oslo", coordinate: CLLocationCoordinate2D(latitude: 59.95, longitude: 10.75), info: "Founded over a thousand years ago.")
        let paris = Capital(title: "Paris", coordinate: CLLocationCoordinate2D(latitude: 48.8567, longitude: 2.3508), info: "Often called the City of Light.")
        let rome = Capital(title: "Rome", coordinate: CLLocationCoordinate2D(latitude: 41.9, longitude: 12.5), info: "Has a whole country inside it.")
        let washington = Capital(title: "Washington DC", coordinate: CLLocationCoordinate2D(latitude: 38.895111, longitude: -77.036667), info: "Named after George himself.")

         mapView.addAnnotations([london, oslo, paris, rome, washington])
    }
}

1 个答案:

答案 0 :(得分:0)

试一下

import UIKit
import MapKit



 class MapViewController: UIViewController {
        @IBOutlet var mapView: MKMapView!

        let location:CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: 20.5937, longitude: 78.9629)


        override func viewDidLoad() {
            super.viewDidLoad()



            let anotation = MKPointAnnotation()
            anotation.coordinate = location
            anotation.title = "The Location"
            anotation.subtitle = "This is the location !!!"
            mapView.addAnnotation(anotation)

        }
}