Manos Chorianopoulos

fix initial location coords values

......@@ -173,6 +173,9 @@ import CoreMotion
orientationCount = 0
touchCount = 0
mLatitude = 0.0
mLongitude = 0.0
}
private func saveAccelerationDataToFile() {
......
......@@ -173,6 +173,9 @@ import CoreMotion
orientationCount = 0
touchCount = 0
mLatitude = 0.0
mLongitude = 0.0
}
private func saveAccelerationDataToFile() {
......@@ -247,7 +250,7 @@ import CoreMotion
}
private func processAccelerometerData(_ accelerationData: CMAccelerometerData) {
// print("=== accelerationData: ",accelerationData)
// print("=== accelerationData: ",accelerationData)
// sensorDataLabel.text = "\(accelerationData.acceleration.x), \(accelerationData.acceleration.y), \(accelerationData.acceleration.z)"
......@@ -273,7 +276,7 @@ import CoreMotion
// TODO: CHECK mayby this is correct
// accelerationLabel.text = String(format: "%.1f m/s^2", acceleration)
// print("=== acceleration: ",acceleration)
// print("=== acceleration: ",acceleration)
// If acceleration is below the stop threshold, assume we are in a stop
// if acceleration < STOP_THRESHOLD {
......@@ -283,7 +286,7 @@ import CoreMotion
velocity = acceleration * time
// }
// print("=== velocity: ",velocity)
// print("=== velocity: ",velocity)
// Convert velocity to km/h
mAcceleration = velocity // Convert to km/h
......@@ -335,6 +338,7 @@ import CoreMotion
private func calculateSpeed(lat1: Double, lon1: Double, lat2: Double, lon2: Double, timeDifferenceInSeconds: Double) -> Double {
let distance = calculateDistance(lat1: lat1, lon1: lon1, lat2: lat2, lon2: lon2)
// print("=== distance: ",distance)
return (distance / timeDifferenceInSeconds) * 3.6 // Convert to km/h
}
......@@ -493,12 +497,14 @@ import CoreMotion
public func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if let location = locations.last {
// print("=== locationManager didUpdateLocations latitude: ",location.coordinate.latitude)
// print("=== locationManager didUpdateLocations longitude: ",location.coordinate.longitude)
// print("=== locationManager didUpdateLocations latitude: ",location.coordinate.latitude)
// print("=== locationManager didUpdateLocations longitude: ",location.coordinate.longitude)
if mLatitude != 0 && mLongitude != 0 {
mSpeed = calculateSpeed(lat1: mLatitude, lon1: mLongitude, lat2: location.coordinate.latitude, lon2: location.coordinate.longitude, timeDifferenceInSeconds: LOCATION_UPDATE_INTERVAL / 1000)
avgVelocityLabel.text = String(format: "%.1f", floor(mSpeed)) + " km/h"
// print("=== mSpeed: ",String(format: "%.1f", floor(mSpeed)) + " km/h")
}
mLatitude = location.coordinate.latitude
......