EDIT:
Im actually getting similar distances when using lat/long calculators. I may be getting bad data to compare my answers to.
Anybody familiar with calculating distances with latitude/longitude in Swift? I'm playing with it here in this code, but I'm getting terrible results. I know that the distance between these two points is about 413.5 meters, but I'm getting results like 3.69 meters.
In the code, I calculate the distances directly from a to B, and then I try to calculate the distance by finding the latitude/longitude component distances and then doing the distance formulas. The component distances are important to my application. I get the same answer doing it directly from a to b and also doing the distance formula, but it is the same wrong answer.
Im actually getting similar distances when using lat/long calculators. I may be getting bad data to compare my answers to.
Anybody familiar with calculating distances with latitude/longitude in Swift? I'm playing with it here in this code, but I'm getting terrible results. I know that the distance between these two points is about 413.5 meters, but I'm getting results like 3.69 meters.
In the code, I calculate the distances directly from a to B, and then I try to calculate the distance by finding the latitude/longitude component distances and then doing the distance formulas. The component distances are important to my application. I get the same answer doing it directly from a to b and also doing the distance formula, but it is the same wrong answer.
Code:
import Foundation
import CoreLocation
let aLong = -96.75626029284595
let aLat = 32.978294210264075
let bLong = -96.75626029812727
let bLat = 32.97826092729531
let a = CLLocation(latitude: aLat, longitude: aLong)
let b = CLLocation(latitude: bLat, longitude: bLong)
let dx = CLLocation(latitude: aLat, longitude: bLong)
let dy = CLLocation(latitude: bLat, longitude: aLong)
let distx = a.distance(from: dx)
let disty = a.distance(from: dy)
let distCalc = pow(pow(distx, 2) + pow(disty, 2), 0.5)
let dist = a.distance(from: b)
print("distx = (distx)")
print("disty = (disty)")
print("distCalc = (distCalc)")
print("dist = (dist)n")