-1

Here, I have different tables firestore but calculating distance from two tables namely Driver_details and Current_booking from firestore. In firestore driver_details table looks like Driver_details -> City(like bangalore, chennai, etc) -> SubLocality(like st.thomas, rajivi street, etc) -> Driver document id -> parameter value(contains: lat, long, name, id, etc..) and Current_booking table looks like Current_booking -> document id -> parameter value(Start_lat, Start_long, etc..).

How can i calculate distance of driver_detaisl -> city -> sublocality and Current_booking of lat long and then filter location driver which is nearest user lat long Here is the screenshots of my firestore db:enter image description here enter image description here

PvDev
  • 791
  • 21
  • 67

1 Answers1

3

I am using the core location.

 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))*

Hope this will help you.

Amrit Tiwari
  • 922
  • 7
  • 21
  • https://stackoverflow.com/questions/33927405/find-closest-longitude-and-latitude-in-array-from-user-location-ios-swift?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa hope it will help you – Amrit Tiwari Apr 18 '18 at 06:20
  • ok. if any problem then fill free to ask the questions and if my answer helps you please mark as accepted :) so it will helps others. – Amrit Tiwari Apr 18 '18 at 06:23
  • Yeah, Thank you very much.. right now i am working on it , if any issue will discuss with you soon... Will mark as answer if it works fine .. – PvDev Apr 18 '18 at 06:25
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/169220/discussion-between-amrit-tiwari-and-pvdev). – Amrit Tiwari Apr 18 '18 at 06:27