【问题标题】:How to calculate distance of two lat long of different table in firestore iOS swift如何在firestore iOS swift中计算两个lat long不同表的距离
【发布时间】:2018-04-18 05:45:16
【问题描述】:

在这里,我有不同的表 firestore,但计算两个表的距离,即来自 firestore 的 Driver_details 和 Current_booking。在 firestore driver_details 表中,Driver_details -> City(如 bangalore、chennai 等)-> SubLocality(如 st.thomas、rajivi street 等)-> Driver 文档 id -> 参数值(包含:lat、long、name、 id 等)和 Current_booking 表看起来像 Current_booking -> 文档 id -> 参数值(Start_lat、Start_long 等)。

如何计算距离 driver_detaisl -> city -> sublocality 和 Current_booking 的 lat long,然后过滤距离最近的用户 lat long 的位置驱动程序 这是我的firestore db的截图:

【问题讨论】:

  • 如果你有两个 cllocation 点,那么你应该计算它们的距离。
  • 是的,那么如何筛选离用户最近的驱动程序?\

标签: ios swift xcode firebase google-cloud-firestore


【解决方案1】:

我正在使用核心位置。

 import CoreLocation

 let driverLocation = CLLocation(latitude: 59.244696, longitude: 17.813868)
 let startLocation = CLLocation(latitude: 59.326354, longitude: 18.072310)

 //this is the distance between driverLocation and startLocation (in km)
 let distance = driverLocation.distance(from: startLocation) / 1000

 //Display the result in km
 print(String(format: "The distance to driver is %.01fkm", distance))*

希望这会对你有所帮助。

【讨论】:

  • 好的。如果有任何问题,请随意填写问题,如果我的回答对您有帮助,请标记为已接受:),这样会对其他人有所帮助。
  • 是的,非常感谢您..我现在正在处理它,如果有任何问题将尽快与您讨论...如果可以正常工作,将标记为答案..
猜你喜欢
  • 2018-11-01
  • 2014-04-04
  • 2013-01-29
  • 1970-01-01
  • 2017-07-03
  • 2020-12-31
  • 2018-12-06
  • 1970-01-01
  • 2016-12-24
相关资源
最近更新 更多