// compute geodetic distance to another place in km
func distanceTo(loc: place) -> Double {
  let R:Double = 6371        
  let geo = loc.getCoordinates()
  let phi1 = deg2rad(self.lat)
  let phi2 = deg2rad(geo.lat)
  let deltaPhi = deg2rad(geo.lat - self.lat)
  let deltaLambda = deg2rad(geo.lon - self.lon)
  let a = sin(deltaPhi / 2) * sin(deltaPhi / 2) + 
    cos(phi1) * cos(phi2) * sin(deltaLambda / 2) * 
    sin(deltaLambda / 2)
  let c = 2 * atan2(sqrt(a), sqrt(1 - a))
  return R * c
}


MathCodingClub.com - Amateur Programming, Mathematics, Physics (until 2019), Philosophy and Enjoying Beer - Since 2014