ios - 无法在 swift 中调用非函数类型 'CLLocationCordinate2d' 的值

标签 ios swift mapkit

我正在尝试向 map 添加两个注释。该 map 工作正常,但当我尝试添加注释时,出现上述错误。这是与此相关的代码部分。

//temporary nearby locations list

        //temple tooth
        var templeToothMarker = MKPointAnnotation()
        var templeToothLocation = CLLocationCoordinate2D(latitude: 7.294715, longitude: 80.639858)
        templeToothMarker.coordinate(templeToothLocation)
        templeToothMarker.title = "Kandy Dalada Maligawa"
        templeToothMarker.subtitle = "Historic Religious place"

        //botanical gardens

        var botanicalGardenMarker = MKPointAnnotation()
        var botanicalGardenLocation = CLLocationCoordinate2D(latitude: 7.294715, longitude: 80.639858)
        botanicalGardenMarker.coordinate(templeToothLocation)
        botanicalGardenMarker.title = "Royal Botanical Gardens"
        botanicalGardenMarker.subtitle = "Historic Religious place"

        //load markers to map
        map.addAnnotations([templeToothMarker, botanicalGardenMarker])

错误出现在

templeToothMarker.coordinate(templeToothLocation)

BotanicalGardenMarker.coordinate(templeToothLocation)

行。我感到困惑,因为我将正确类型的参数传递给 coordinate 方法。这里可能出了什么问题?

最佳答案

这很简单。坐标它是一个属性,而不是一个方法。你只需要设置如下:

botanicalGardenMarker.coordinate = botanicalGardenLocation

关于ios - 无法在 swift 中调用非函数类型 'CLLocationCordinate2d' 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34773736/

相关文章:

ios - 如何计算 iOS 中的事件线程数

php - 使用 PHP 在 Swift 中接收 POST

iphone - map 套件 : Custom placemarks

iphone - 如果用户说 "no",如何让位置服务继续提示

swift - MKAnnotationView 子类在 Swift 中应该有哪些初始值设定项?

ios - Parse.com iOS queryWithClassName 适用于某些人,但不适用于其他人,为什么?

iphone - 添加没有 PKAddPassesViewController 实例的通行证

ios - Collection View 单元格边框颜色在 Swift 3 中取消选择

swift - 按位运算类型中的 Self 是什么?

swift - 本地通知在计划外时间多次触发