如何获得注释以xcode显示在地图上?

问题描述 投票:1回答:1

我正在尝试获取某些内容的注释,但它给出了我不知道如何消除的错误,有人碰巧知道如何解决此问题吗?

这是我当前拥有的代码,但是它说类型'MKPointAnnotation'的值没有成员'setCoordinate'。它说:使用未解析的标识符“ map”。

import UIKit
import MapKit
import CoreLocation

class ViewController: UIViewController {

    @IBOutlet var Map: MKMapView!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.

        var WCAula = CLLocationCoordinate2DMake(50.3044, 4.5724)
        // These are the lattitude and longitude of the toilet across the wooden stairs in the auditorium.

        var point1 = MKPointAnnotation()
        point1.setCoordinate(WCAula)
        point1.title = "WCAula"

        map.addAnnotation(point1)
    }
}
swift xcode mkmapview mkannotation
1个回答
0
投票

您定义的地图视图以大写字母M开头,而您引用的地图以小写字母m开头。对其进行更改,使它们都小写,这是Swift中的惯例。

就设置坐标而言,调用setCoordinate()是Objective-C语法。在Swift中,您可以直接设置坐标。

point1.coordinate = WCAula
© www.soinside.com 2019 - 2024. All rights reserved.