Merge pull request #657 from hargata/Hargata/gps.integration

fixes for GPS integration and experimental feature banner.
This commit is contained in:
Hargata Softworks
2024-10-20 19:12:47 -06:00
committed by GitHub
4 changed files with 45 additions and 7 deletions

View File

@@ -92,5 +92,18 @@ namespace CarCareTracker.Controllers
}
return Path.Combine("/", uploadDirectory, fileName);
}
public IActionResult UploadCoordinates(List<string> coordinates)
{
string uploadDirectory = "temp/";
string uploadPath = Path.Combine(_webEnv.WebRootPath, uploadDirectory);
if (!Directory.Exists(uploadPath))
Directory.CreateDirectory(uploadPath);
string fileName = Guid.NewGuid() + ".csv";
string filePath = Path.Combine(uploadPath, fileName);
string fileData = string.Join("\r\n", coordinates);
System.IO.File.WriteAllText(filePath, fileData);
var uploadedFile = new UploadedFiles { Name = "coordinates.csv", Location = Path.Combine("/", uploadDirectory, fileName) };
return Json(uploadedFile);
}
}
}

View File

@@ -12,6 +12,14 @@
<button type="button" class="btn-close" onclick="hideAddOdometerRecordModal()" aria-label="Close"></button>
</div>
<div class="modal-body d-none trip-modal">
<div class="row">
<div class="col-12">
<div class="alert alert-warning alert-dismissable" role="alert">
@translator.Translate(userLanguage, "Experimental Feature - Your browser must be granted access to your precise location and support Geolocation and Wakelock API for this feature to function. Do not exit or minimize this app when recording. Verify all starting and ending odometers. Accuracy subject to hardware limitations.")
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
</div>
</div>
<div class="row">
<div class="col-12 d-flex justify-content-center">
<h1 class="display-6 text-body-secondary">@translator.Translate(userLanguage, "Current Odometer")</h1>
@@ -20,7 +28,7 @@
<div class="row">
<div class="col-12 d-flex justify-content-center align-items-center">
<h1 class="display-1 trip-odometer"></h1>
<h1 class="display-6 trip-odometer-sub ms-2">0</h1>
<h1 class="display-6 trip-odometer-sub ms-2 d-none">0</h1>
</div>
</div>
</div>

File diff suppressed because one or more lines are too long

View File

@@ -226,6 +226,7 @@ function showTripModal() {
$(".trip-odometer").text($("#initialOdometerRecordMileage").val());
}
function hideTripModal() {
stopRecording();
$(".odometer-modal").removeClass('d-none');
$(".trip-modal").addClass('d-none');
}
@@ -233,6 +234,7 @@ function hideTripModal() {
let tripTimer; //interval to check GPS Location every 5 seconds.
let tripWakeLock; //wakelock handler to prevent screen from going to sleep.
let tripLastPosition; //last coordinates to compare/calculate distance from.
let tripCoordinates = [ "Latitude,Longitude" ]; //list of coordinates to generate a CSV for.
function startRecording() {
if (navigator.geolocation && navigator.wakeLock) {
try {
@@ -259,17 +261,24 @@ function recordPosition(position) {
latitude: currentLat,
longitude: currentLong
}
tripCoordinates.push(`${currentLat},${currentLong}`);
} else {
//calculate distance
var distanceTraveled = calculateDistance(tripLastPosition.latitude, tripLastPosition.longitude, currentLat, currentLong);
var recordedTotalOdometer = getRecordedOdometer();
if (distanceTraveled > 0.1) { //if greater than 0.1 mile or KM then it's significant
recordedTotalOdometer += distanceTraveled.toFixed(1);
var recordedOdometerString = recordedTotalOdometer.toString().split('.');
if (distanceTraveled >= 0.1) { //if greater than 0.1 mile or KM then it's significant
recordedTotalOdometer += parseFloat(distanceTraveled.toFixed(3));
var recordedOdometerString = recordedTotalOdometer.toFixed(3).toString().split('.');
$(".trip-odometer").html(recordedOdometerString[0]);
if (recordedOdometerString.length > 2) {
if (recordedOdometerString.length == 2) {
$(".trip-odometer-sub").html(recordedOdometerString[1]);
}
//update last position
tripLastPosition = {
latitude: currentLat,
longitude: currentLong
}
tripCoordinates.push(`${currentLat},${currentLong}`);
}
}
}
@@ -313,6 +322,14 @@ function getRecordedOdometer() {
return parseFloat(`${recordedOdometer}.${recordedSubOdometer}`);
}
function saveRecordedOdometer() {
$("#initialOdometerRecordMileage").val(getRecordedOdometer());
//update current odometer value
$("#odometerRecordMileage").val(parseInt(getRecordedOdometer()).toString());
//save coordinates into a CSV file and upload
$.post('/Files/UploadCoordinates', { coordinates: tripCoordinates }, function (response) {
uploadedFiles.push(response);
$.post('/Vehicle/GetFilesPendingUpload', { uploadedFiles: uploadedFiles }, function (viewData) {
$("#filesPendingUpload").html(viewData);
});
});
hideTripModal();
}