我正在使用 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/