ios - 是否有预设的“索引”或类似的东西可以让我引用用户创建的特定注释?斯威夫特 4
问题描述
我有一个应用程序,用户可以在其中搜索位置,点击表格视图中的行,然后在地标处放置注释。我有一个按钮“meetUpButton”,它允许他们放置多个注释,而不是我的代码默认执行的操作,即在单击新搜索结果时删除注释。有没有办法引用我的用户创建的特定注释,即使他们做了多个?例如,假设我想添加我的用户创建的两个注释的纬度......如果我有
let annotation = MKPointAnnotation()
annotation.coordinate.latitude
有没有办法引用索引为 0 的第一个注释和我的用户用 1 或其他方式选择的下一个注释?这是我的一些代码,可能会使这更清楚。
extension ViewController: handleMapSearch {
func dropPinZoomIn(placemark:MKPlacemark) {
resultSearchController?.isActive = false
// cache the pin
selectedPin = placemark
// clear existing pins
if meetUpOutlet.isEnabled == true {
mapView.removeAnnotations(mapView.annotations)
} else {
}
let annotation = MKPointAnnotation()
annotation.coordinate = placemark.coordinate
annotation.title = placemark.name
if let city = placemark.locality,
let state = placemark.administrativeArea {
annotation.subtitle = "(\(city)) (\(state))"
}
mapView.addAnnotation(annotation)
let span = MKCoordinateSpanMake(0.05, 0.05)
let region = MKCoordinateRegionMake(placemark.coordinate, span)
mapView.setRegion(region, animated: true)
}
}
解决方案
您可以尝试使用实例annotations
的属性MKMapView
,以获得所有使用
let anns = self.mapView.annotations
推荐阅读
- flutter - 我的 AppBar 在屏幕上的图像后面,或者我看不到它,有什么建议可以在顶部显示我的 AppBar 和 buttonNavigator 并且是半透明的吗?
- google-sheets - 如何使用条件格式在 Google 表格的 1 列中突出显示部分匹配的重复项
- html - 在有两个标题的表格中,主标题不会在滚动时保持粘性
- python - 如何改变盒子的不透明度(cv2.rectangle)?
- java - 如何修复:java.lang.ClassCastException:androidx.appcompat.widget.AppCompatTextView 无法转换为 android.widget.Button
- python-3.x - 循环遍历 csv 数据
- ios - defer 语句的不同行为
- node.js - 如何使用 ckeditor 在 mongoose-node 应用程序中上传图像。文件将上传到 s3
- qt - 使用 QMediaplayer 从缓冲区播放视频并在视频播放时附加缓冲区
- c# - 从字符串中删除 HTML -- 注释