我正在尝试确定当前在mapview中显示的标记。我研究了以下方法:
self.mapView.bounds.contains(markers[0].position)
但是contains
命令接受CGPoint或CGRect。在除Swift之外的其他平台中,contains
可以接受标记的位置。
如何将标记的位置转换为contains
接受?
答案 0 :(得分:8)
使用mapview的当前urlList
。使用名为projection
的投影方法检查您的标记位置是否在投影内,a.k.a。当前可见。
类似于:
containsCoordinate
答案 1 :(得分:2)
在MapKit中:
我认为Marker是指MKAnnotation
。您应该使用mapView
而不是使用visibleMapRect
的范围,并查看它是否包含MKMapPoints
中标记的坐标。这是我使用的代码:
let markerPoint = MKMapPointForCoordinate(markers[0].coordinate)
if MKMapRectContainsPoint(mapView.visibleMapRect, markerPoint) {
print("Found")
} else {
print("Not found")
}
只有当标记的坐标可见时(换句话说,正在显示标记),才会打印“找到”。如果屏幕外,它将打印“未找到”。