【问题标题】:Calculating total latitude/longitude of annotations in Swift 4 mapKit?在 Swift 4 mapKit 中计算注释的总纬度/经度?
【发布时间】:2018-10-05 22:53:58
【问题描述】:

所以我有一个使用 mapKit 的导航应用程序,并且我有一个按钮,允许用户根据需要添加多个注释。我应该补充一点,他们通过在搜索表中搜索一个位置并按下它,创建注释来添加这些,就像法线贴图应用程序一样。我的按钮允许他们添加多个。

1) 如何添加每个注释的纬度/经度?我在想一些类似于

的东西
let totalLatitude = mapView.annotations.reduce etc etc

这行得通吗?

2) 如果是reduce,我应该使用什么参数?

3) 我怎样才能把它放在一个允许我指定 mapView.annotations.coordinate.latitude 等的形式中?

4) 我知道您不能将 .coordinate 与 .annotations 放在一起...所以还有其他方法吗?谢谢

【问题讨论】:

  • 添加所有注释的纬度/经度是什么意思?这似乎不是一个有意义的值。您是否要计算所有输入点的纬度/经度的总跨度? (点的“足迹”)?

标签: arrays swift annotations mapkit


【解决方案1】:

如果你的意思是你想要所有注释的纬度/经度之和:

let totalLatitudes = mapView.annotations.reduce(0) { $0 + $1.coordinate.latitude }

let totalLongitudes = mapView.annotations.reduce(0) { $0 + $1.coordinate.longitude }

【讨论】:

  • “总纬度”或“总经度”是什么意思?没什么,真的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-09-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多