'MKAnnotation' 类型的值没有成员 'latitude'
Value of type 'MKAnnotation' has no member 'latitude'
我将 XCode 更新为 7 和 BAM.. 很多错误。
其中之一是注释不再具有纬度和经度成员。这在更新之前就像一个魅力,所以我不知道该去哪里。
这里的问题是我正在查看当前地图上的所有注释,并尝试过滤已固定在地图上的特定纬度和经度位置。
var existingPins = self.mapView.annotations.filter {m in m.latitude == getLocation.latitude! && m.longitude == getLocation.longitude! }
我不得不认为还有另一个我不熟悉的角度来获取这些坐标。我将继续搜索,但非常感谢任何帮助。
MKAnnotation
是一种协议,因此无论您使用哪种类型实现该协议,都可能是提供纬度方法的任何类型。 MKAnnotation
不包含 latitude
方法,但它确实需要 coordinate
方法,returns 和 CLLocationCoordinate2D
, 需要包括纬度成员。
没有看到你的代码,我猜你有两个选择:
- 将
m.latitude
调用更改为 m.coordinate.latitude
。
- 使用
as?
或 as!
运算符将注释作为实际实现 MKAnnotation
. 的任何自定义类型
永远不会失败,我花了几个小时摸不着头脑,我 post 这个问题,几分钟后我就想通了。
"m" 是一个特定的注释,我需要指定其中包含 lat/lon 的坐标成员。
此外,我需要将传入的值转换为双精度值,以便进行比较。我不确定在 xcode 7 之前这是如何工作的。
这里是修改后的代码。
let existingPins = self.mapView.annotations.filter {m in m.coordinate.latitude == Double(getLocation.latitude!) && m.coordinate.longitude == Double(getLocation.longitude!) }
我将 XCode 更新为 7 和 BAM.. 很多错误。
其中之一是注释不再具有纬度和经度成员。这在更新之前就像一个魅力,所以我不知道该去哪里。
这里的问题是我正在查看当前地图上的所有注释,并尝试过滤已固定在地图上的特定纬度和经度位置。
var existingPins = self.mapView.annotations.filter {m in m.latitude == getLocation.latitude! && m.longitude == getLocation.longitude! }
我不得不认为还有另一个我不熟悉的角度来获取这些坐标。我将继续搜索,但非常感谢任何帮助。
MKAnnotation
是一种协议,因此无论您使用哪种类型实现该协议,都可能是提供纬度方法的任何类型。 MKAnnotation
不包含 latitude
方法,但它确实需要 coordinate
方法,returns 和 CLLocationCoordinate2D
, 需要包括纬度成员。
没有看到你的代码,我猜你有两个选择:
- 将
m.latitude
调用更改为m.coordinate.latitude
。 - 使用
as?
或as!
运算符将注释作为实际实现MKAnnotation
. 的任何自定义类型
永远不会失败,我花了几个小时摸不着头脑,我 post 这个问题,几分钟后我就想通了。
"m" 是一个特定的注释,我需要指定其中包含 lat/lon 的坐标成员。
此外,我需要将传入的值转换为双精度值,以便进行比较。我不确定在 xcode 7 之前这是如何工作的。
这里是修改后的代码。
let existingPins = self.mapView.annotations.filter {m in m.coordinate.latitude == Double(getLocation.latitude!) && m.coordinate.longitude == Double(getLocation.longitude!) }