Toggle navigation
Toggle navigation
This project
Loading...
Sign in
open-source
/
warply_sdk_framework
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
Manos Chorianopoulos
2023-11-13 15:45:23 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
4cf6657afe7f957b64031d5f502bdba98d8ef4e5
4cf6657a
1 parent
e1466ec3
velocity fixes
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
5 deletions
SwiftWarplyFramework/SwiftWarplyFramework/TelematicsViewController.swift
SwiftWarplyFramework/SwiftWarplyFramework/TelematicsViewController.swift
View file @
4cf6657
...
...
@@ -337,16 +337,42 @@ 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
)
// let distance = calculateDistance(lat1: lat1, lon1: lon1, lat2: lat2, lon2: lon2)
let
distance
=
distanceInKmBetweenEarthCoordinates
(
lat1
:
lat1
,
lon1
:
lon1
,
lat2
:
lat2
,
lon2
:
lon2
)
// print("=== distance: ",distance)
return
(
distance
/
timeDifferenceInSeconds
)
*
3.6
// Convert to km/h
}
private
func
calculateDistance
(
lat1
:
Double
,
lon1
:
Double
,
lat2
:
Double
,
lon2
:
Double
)
->
Double
{
let
x
=
(
lon2
-
lon1
)
.
toRadians
()
*
cos
(((
lat1
+
lat2
)
/
2
)
.
toRadians
())
let
y
=
(
lat2
-
lat1
)
.
toRadians
()
return
sqrt
(
x
*
x
+
y
*
y
)
*
EARTH_RADIUS
// MARK: distance implementation no1 ===>
// private func calculateDistance(lat1: Double, lon1: Double, lat2: Double, lon2: Double) -> Double {
// let x = (lon2 - lon1).toRadians() * cos(((lat1 + lat2) / 2).toRadians())
// let y = (lat2 - lat1).toRadians()
// return sqrt(x * x + y * y) * EARTH_RADIUS
// }
// <===
// MARK: distance implementation no2 ===>
func
degreesToRadians
(
degrees
:
Double
)
->
Double
{
return
degrees
*
Double
.
pi
/
180
}
func
distanceInKmBetweenEarthCoordinates
(
lat1
:
Double
,
lon1
:
Double
,
lat2
:
Double
,
lon2
:
Double
)
->
Double
{
let
earthRadiusKm
:
Double
=
6371
let
dLat
=
degreesToRadians
(
degrees
:
lat2
-
lat1
)
let
dLon
=
degreesToRadians
(
degrees
:
lon2
-
lon1
)
let
lat1
=
degreesToRadians
(
degrees
:
lat1
)
let
lat2
=
degreesToRadians
(
degrees
:
lat2
)
let
a
=
sin
(
dLat
/
2
)
*
sin
(
dLat
/
2
)
+
sin
(
dLon
/
2
)
*
sin
(
dLon
/
2
)
*
cos
(
lat1
)
*
cos
(
lat2
)
let
c
=
2
*
atan2
(
sqrt
(
a
),
sqrt
(
1
-
a
))
return
earthRadiusKm
*
c
}
// <===
// Orientation Observer
func
setupOrientationChangeDetection
()
{
...
...
@@ -510,6 +536,26 @@ import CoreMotion
mLatitude
=
location
.
coordinate
.
latitude
mLongitude
=
location
.
coordinate
.
longitude
}
// MARK: distance implementation no3 ===>
// Get the current location
// if let currentLocation = locationManager.location {
// // Get the speed in meters per second
// let speed = currentLocation.speed
// // Convert the speed to kilometers per hour
// let speedInKmPerHour = speed * 3.6
//
// if (speedInKmPerHour >= 0.0) {
// mSpeed = speedInKmPerHour
// } else {
// mSpeed = 0.0
// }
//
// avgVelocityLabel.text = String(format: "%.1f", floor(mSpeed)) + " km/h"
//
//// print("=== speedInKmPerHour: ",String(format: "%.1f", floor(speedInKmPerHour)) + " km/h")
// }
// <===
}
public
func
locationManager
(
_
manager
:
CLLocationManager
,
didFailWithError
error
:
Error
)
{
...
...
Please
register
or
login
to post a comment