Showing
2 changed files
with
14 additions
and
5 deletions
| ... | @@ -173,6 +173,9 @@ import CoreMotion | ... | @@ -173,6 +173,9 @@ import CoreMotion |
| 173 | 173 | ||
| 174 | orientationCount = 0 | 174 | orientationCount = 0 |
| 175 | touchCount = 0 | 175 | touchCount = 0 |
| 176 | + | ||
| 177 | + mLatitude = 0.0 | ||
| 178 | + mLongitude = 0.0 | ||
| 176 | } | 179 | } |
| 177 | 180 | ||
| 178 | private func saveAccelerationDataToFile() { | 181 | private func saveAccelerationDataToFile() { | ... | ... |
| ... | @@ -173,6 +173,9 @@ import CoreMotion | ... | @@ -173,6 +173,9 @@ import CoreMotion |
| 173 | 173 | ||
| 174 | orientationCount = 0 | 174 | orientationCount = 0 |
| 175 | touchCount = 0 | 175 | touchCount = 0 |
| 176 | + | ||
| 177 | + mLatitude = 0.0 | ||
| 178 | + mLongitude = 0.0 | ||
| 176 | } | 179 | } |
| 177 | 180 | ||
| 178 | private func saveAccelerationDataToFile() { | 181 | private func saveAccelerationDataToFile() { |
| ... | @@ -247,7 +250,7 @@ import CoreMotion | ... | @@ -247,7 +250,7 @@ import CoreMotion |
| 247 | } | 250 | } |
| 248 | 251 | ||
| 249 | private func processAccelerometerData(_ accelerationData: CMAccelerometerData) { | 252 | private func processAccelerometerData(_ accelerationData: CMAccelerometerData) { |
| 250 | - // print("=== accelerationData: ",accelerationData) | 253 | +// print("=== accelerationData: ",accelerationData) |
| 251 | 254 | ||
| 252 | // sensorDataLabel.text = "\(accelerationData.acceleration.x), \(accelerationData.acceleration.y), \(accelerationData.acceleration.z)" | 255 | // sensorDataLabel.text = "\(accelerationData.acceleration.x), \(accelerationData.acceleration.y), \(accelerationData.acceleration.z)" |
| 253 | 256 | ||
| ... | @@ -273,7 +276,7 @@ import CoreMotion | ... | @@ -273,7 +276,7 @@ import CoreMotion |
| 273 | // TODO: CHECK mayby this is correct | 276 | // TODO: CHECK mayby this is correct |
| 274 | // accelerationLabel.text = String(format: "%.1f m/s^2", acceleration) | 277 | // accelerationLabel.text = String(format: "%.1f m/s^2", acceleration) |
| 275 | 278 | ||
| 276 | - // print("=== acceleration: ",acceleration) | 279 | +// print("=== acceleration: ",acceleration) |
| 277 | 280 | ||
| 278 | // If acceleration is below the stop threshold, assume we are in a stop | 281 | // If acceleration is below the stop threshold, assume we are in a stop |
| 279 | // if acceleration < STOP_THRESHOLD { | 282 | // if acceleration < STOP_THRESHOLD { |
| ... | @@ -283,7 +286,7 @@ import CoreMotion | ... | @@ -283,7 +286,7 @@ import CoreMotion |
| 283 | velocity = acceleration * time | 286 | velocity = acceleration * time |
| 284 | // } | 287 | // } |
| 285 | 288 | ||
| 286 | - // print("=== velocity: ",velocity) | 289 | +// print("=== velocity: ",velocity) |
| 287 | 290 | ||
| 288 | // Convert velocity to km/h | 291 | // Convert velocity to km/h |
| 289 | mAcceleration = velocity // Convert to km/h | 292 | mAcceleration = velocity // Convert to km/h |
| ... | @@ -335,6 +338,7 @@ import CoreMotion | ... | @@ -335,6 +338,7 @@ import CoreMotion |
| 335 | 338 | ||
| 336 | private func calculateSpeed(lat1: Double, lon1: Double, lat2: Double, lon2: Double, timeDifferenceInSeconds: Double) -> Double { | 339 | private func calculateSpeed(lat1: Double, lon1: Double, lat2: Double, lon2: Double, timeDifferenceInSeconds: Double) -> Double { |
| 337 | let distance = calculateDistance(lat1: lat1, lon1: lon1, lat2: lat2, lon2: lon2) | 340 | let distance = calculateDistance(lat1: lat1, lon1: lon1, lat2: lat2, lon2: lon2) |
| 341 | +// print("=== distance: ",distance) | ||
| 338 | return (distance / timeDifferenceInSeconds) * 3.6 // Convert to km/h | 342 | return (distance / timeDifferenceInSeconds) * 3.6 // Convert to km/h |
| 339 | } | 343 | } |
| 340 | 344 | ||
| ... | @@ -493,12 +497,14 @@ import CoreMotion | ... | @@ -493,12 +497,14 @@ import CoreMotion |
| 493 | 497 | ||
| 494 | public func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { | 498 | public func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { |
| 495 | if let location = locations.last { | 499 | if let location = locations.last { |
| 496 | - // print("=== locationManager didUpdateLocations latitude: ",location.coordinate.latitude) | 500 | +// print("=== locationManager didUpdateLocations latitude: ",location.coordinate.latitude) |
| 497 | - // print("=== locationManager didUpdateLocations longitude: ",location.coordinate.longitude) | 501 | +// print("=== locationManager didUpdateLocations longitude: ",location.coordinate.longitude) |
| 498 | 502 | ||
| 499 | if mLatitude != 0 && mLongitude != 0 { | 503 | if mLatitude != 0 && mLongitude != 0 { |
| 500 | mSpeed = calculateSpeed(lat1: mLatitude, lon1: mLongitude, lat2: location.coordinate.latitude, lon2: location.coordinate.longitude, timeDifferenceInSeconds: LOCATION_UPDATE_INTERVAL / 1000) | 504 | mSpeed = calculateSpeed(lat1: mLatitude, lon1: mLongitude, lat2: location.coordinate.latitude, lon2: location.coordinate.longitude, timeDifferenceInSeconds: LOCATION_UPDATE_INTERVAL / 1000) |
| 501 | avgVelocityLabel.text = String(format: "%.1f", floor(mSpeed)) + " km/h" | 505 | avgVelocityLabel.text = String(format: "%.1f", floor(mSpeed)) + " km/h" |
| 506 | + | ||
| 507 | +// print("=== mSpeed: ",String(format: "%.1f", floor(mSpeed)) + " km/h") | ||
| 502 | } | 508 | } |
| 503 | 509 | ||
| 504 | mLatitude = location.coordinate.latitude | 510 | mLatitude = location.coordinate.latitude | ... | ... |
-
Please register or login to post a comment