I need to calculate person location primarily based on iBeacon information and Accuracy. At this second i’ve 2 iBeacon sensor(however sooner or later i’ll use 3 iBeacons for calculation person location), every iBeacon has personal location and primarily based on location and sign(Accuracy) i need to calculate person location.
For take a look at, i create methodology
func determineLocation() -> CLLocationCoordinate2D? {
let beacon1 = CLLocation(latitude: 51.78889022813119, longitude: 19.440722653352616)
let beacon2 = CLLocation(latitude: 51.788790844937374, longitude: 19.440694676783878)
let beacon1Accuracy = 2.0
let beacon2Accuracy = 3.0
let x1 = beacon1.coordinate.latitude
let y1 = beacon1.coordinate.longitude
let r1 = beacon1Accuracy
let x2 = beacon2.coordinate.latitude
let y2 = beacon2.coordinate.longitude
let r2 = beacon2Accuracy
// Calculate the person's location utilizing trilateration
let A = 2 * x2 - 2 * x1
let B = 2 * y2 - 2 * y1
let C = pow(r1, 2) - pow(r2, 2) - pow(x1, 2) + pow(x2, 2) - pow(y1, 2) + pow(y2, 2)
let x = C * B / (pow(B, 2) + pow(A, 2))
let y = C * A / (pow(B, 2) + pow(A, 2))
// Create a CLLocationCoordinate2D object with the person's location
let location = CLLocationCoordinate2D(latitude: x, longitude: y)
return location
}
however this methodology return incorrect location, it seems to be like this:
latitude: 25939.440985715428, longitude: 84509.21179857382
Are you able to please assist me discover what the issue, and possibly if somebody know libraries which might help it will likely be good(iOS, Android additionally might be nice)