【发布时间】:2018-06-24 14:42:37
【问题描述】:
当且仅当 mapview 上没有相同的 pin 以避免在同一位置有多个重复注释时,我才尝试将注释 pin 添加到 Mapview。
谁能帮帮我?
【问题讨论】:
标签: swift annotations mapkit
当且仅当 mapview 上没有相同的 pin 以避免在同一位置有多个重复注释时,我才尝试将注释 pin 添加到 Mapview。
谁能帮帮我?
【问题讨论】:
标签: swift annotations mapkit
你可以使用mapView.view(for:)方法。
例如
if (self.mapView.view(for: annotation) != nil) {
print("pin already on mapview")
}
【讨论】:
@Kosuke Ogawa 建议的方法可行。但是,依靠 UI 确定应用程序状态并不是一个好主意。
例如:您很可能在视图控制器的某种数据结构中存储了一个注释列表(我猜是一个数组)。这个数据结构应该是真相的来源。
在您的情况下,要确定地图上是否已经存在注释,请检查提供地图视图的数据结构是否包含注释并继续。
【讨论】: