mirror of
https://github.com/hargata/lubelog.git
synced 2025-12-10 00:46:08 -06:00
Fix distance accuracy
This commit is contained in:
parent
cbbd7ff25f
commit
f90ddeabb4
@ -283,11 +283,16 @@ function recordPosition(position) {
|
|||||||
var distanceTraveled = calculateDistance(tripLastPosition.latitude, tripLastPosition.longitude, currentLat, currentLong);
|
var distanceTraveled = calculateDistance(tripLastPosition.latitude, tripLastPosition.longitude, currentLat, currentLong);
|
||||||
var recordedTotalOdometer = getRecordedOdometer();
|
var recordedTotalOdometer = getRecordedOdometer();
|
||||||
if (distanceTraveled >= 0.1) { //if greater than 0.1 mile or KM then it's significant
|
if (distanceTraveled >= 0.1) { //if greater than 0.1 mile or KM then it's significant
|
||||||
recordedTotalOdometer += parseFloat(distanceTraveled.toFixed(3));
|
recordedTotalOdometer += distanceTraveled;
|
||||||
var recordedOdometerString = recordedTotalOdometer.toFixed(3).toString().split('.');
|
var recordedOdometerString = recordedTotalOdometer.toString().split('.');
|
||||||
$(".trip-odometer").html(recordedOdometerString[0]);
|
$(".trip-odometer").html(recordedOdometerString[0]);
|
||||||
if (recordedOdometerString.length == 2) {
|
if (recordedOdometerString.length == 2) {
|
||||||
$(".trip-odometer-sub").html(recordedOdometerString[1]);
|
if (recordedOdometerString[1].toString().length > 3) {
|
||||||
|
$(".trip-odometer-sub").html(recordedOdometerString[1].toString().substring(0, 3));
|
||||||
|
} else {
|
||||||
|
$(".trip-odometer-sub").html(recordedOdometerString[1].toString());
|
||||||
|
}
|
||||||
|
$(".trip-odometer-sub").attr("data-value", recordedOdometerString[1]);
|
||||||
}
|
}
|
||||||
//update last position
|
//update last position
|
||||||
tripLastPosition = {
|
tripLastPosition = {
|
||||||
@ -349,8 +354,8 @@ function calculateDistance(lat1, lon1, lat2, lon2) {
|
|||||||
return Math.abs(calculatedDistance);
|
return Math.abs(calculatedDistance);
|
||||||
}
|
}
|
||||||
function getRecordedOdometer() {
|
function getRecordedOdometer() {
|
||||||
var recordedOdometer = parseInt($(".trip-odometer").html());
|
var recordedOdometer = $(".trip-odometer").html();
|
||||||
var recordedSubOdometer = parseInt($(".trip-odometer-sub").html());
|
var recordedSubOdometer = $(".trip-odometer-sub").attr("data-value");
|
||||||
return parseFloat(`${recordedOdometer}.${recordedSubOdometer}`);
|
return parseFloat(`${recordedOdometer}.${recordedSubOdometer}`);
|
||||||
}
|
}
|
||||||
function saveRecordedOdometer() {
|
function saveRecordedOdometer() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user