ios - 如何修复 "Instance member ' coordinate' cannot be used on type 'MKMapPoint' “Swift 5.0 中的错误

标签 ios swift xcode mapkit

我正在使用 Apple 的 Footprint: Indoor Positioning with Core Location sample code构建移动应用程序。此代码采用 Swift 3.0,我正在将其转换为 Swift 5.0 语法。 当我运行这段 Swift 3.0 代码时,

coordinate = MKCoordinateForMapPoint(boundingMapRect.getCenter())

我收到这个错误。

“MKCoordinateForMapPoint' has been replaced by property 'MKMapPoint.coordinate'”

当我将语法更改为

coordinate = MKMapPoint.coordinate (boundingMapRect.getCenter())

我收到此错误消息

“Instance member 'coordinate' cannot be used on type 'MKMapPoint'”

如何让这行代码运行?

最佳答案

Apple 在 MKMapRect 的扩展中定义了 getCenter():

extension MKMapRect {
    /**
        - returns: The point at the center of the rectangle.
        - parameter rect: A rectangle.
    */
    func getCenter() -> MKMapPoint {
        return MKMapPointMake(MKMapRectGetMidX(self), MKMapRectGetMidY(self))
        // now return MKMapPoint(x: self.midX, y: self.midY)
    }
}

因为 getCenter() 返回一个 MKMapPoint,你只需要访问它的 coordinate 属性:

coordinate = boundingMapRect.getCenter().coordinate

关于ios - 如何修复 "Instance member ' coordinate' cannot be used on type 'MKMapPoint' “Swift 5.0 中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56917469/

相关文章:

xcode - 无法转换类型的值,swift 2.0,错误处理

iphone - 具有相同代码库的两个 iPhone 应用程序

ios - 自定义google登录按钮:将按钮颜色更改为红色g +登录IOS SDK

ios - 使用 swift 4 在 VIPER 中进行 dataTaskWithURL 崩溃单元测试

swift - 检查[字符串: AnyObject] dictionary for a list of keys with values of specific types?

ios - HUD 中的文本颜色

objective-c - 多部分 POST 和 objective-c

iphone - 滑动删除 UITableView

iphone - 给pdf添加注释

swift - NavigationView 的内容未显示 SwiftUI