0

i have 2 latitude obtain on this format:

let lat1 = 37.33756323
let lat2 = 37.33683958

now I need to calculate the distance between this 2 point.

converting this to hours, min and second I'm able to calculate the distance .. which result in around 0.08km considering that for 1 deg of lat = 60 NM

But how can I do it with swift.. is there any way to first convert this lat in hours, min and second? I can't find the right way to "subtract" correctly this 2 angles.

any suggestion?

thanks a lot

Damiano Miazzi
  • 1,514
  • 1
  • 16
  • 38
  • have a look at: https://stackoverflow.com/questions/45533739/calculate-distance-between-2-point-on-maps-for-ios using Swift `CLLocation`. Note you also need longitudes to calculate distances. – workingdog support Ukraine Mar 19 '22 at 06:43
  • 1
    Do you need the distance in degrees or in km? If in km, why do you want to convert to degrees first? Just calculate `abs(lat1 - lat2) * 111` – derpirscher Mar 19 '22 at 06:53

1 Answers1

0

from the code at: Calculate distance between 2 point on maps for iOS

import CoreLocation 

let lat1 = 37.33756323
let lat2 = 37.33683958

let coord0 = CLLocation(latitude: lat1, longitude: 0.0)
let coord1 = CLLocation(latitude: lat2, longitude: 0.0)
let d = coord0.distance(from: coord1)

print("\n----> d = \(d) (m) ")  // 80.31355191695503 meters
print("----> d = \(d/1000.0) (km) \n") // 0.08031355191695504 kilometers