Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 无法在Swift中显示地图批注_Ios_Swift_Mapkit_Mapkitannotation - Fatal编程技术网

Ios 无法在Swift中显示地图批注

Ios 无法在Swift中显示地图批注,ios,swift,mapkit,mapkitannotation,Ios,Swift,Mapkit,Mapkitannotation,我正在尝试添加地图批注,但当我尝试运行应用程序时,地图批注不会显示,并给出错误消息 添加地图批注[3668:68848]无法从中插入合法属性 拐角4 事实上,我只是在Youtube上看了一个教程,在swift3中,这个代码似乎有效,但我不知道为什么它在我身上不起作用。我使用的是swift 4和Xcode 9.2 我已经尝试了一个来自堆栈溢出的解决方案,但它在我这里不起作用 这里出了什么问题 import UIKit import MapKit class ViewController: UIV

我正在尝试添加地图批注,但当我尝试运行应用程序时,地图批注不会显示,并给出错误消息

添加地图批注[3668:68848]无法从中插入合法属性 拐角4

事实上,我只是在Youtube上看了一个教程,在swift3中,这个代码似乎有效,但我不知道为什么它在我身上不起作用。我使用的是swift 4和Xcode 9.2

我已经尝试了一个来自堆栈溢出的解决方案,但它在我这里不起作用

这里出了什么问题

import UIKit
import MapKit

class ViewController: UIViewController {


    @IBOutlet weak var mapKitView: MKMapView!



    override func viewDidLoad() {
        super.viewDidLoad()

        let span : MKCoordinateSpan = MKCoordinateSpanMake(0.001, 0.001)
        let location : CLLocationCoordinate2D = CLLocationCoordinate2DMake(-6.239116, 106.789415)
        let region : MKCoordinateRegion = MKCoordinateRegionMake(location, span)
        mapKitView.setRegion(region, animated: true)

        let annotation =  MKPointAnnotation()
        annotation.title = "My Shop"
        annotation.subtitle = "Come visit here"
        mapKitView.addAnnotation(annotation)

    }




}
你是说:

    let annotation =  MKPointAnnotation()
    annotation.title = "My Shop"
    annotation.subtitle = "Come visit here"
    mapKitView.addAnnotation(annotation)
这就是你要说的。但是那个注释没有坐标!那么你认为地图怎么可能知道它应该去哪里呢