mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-04-20 22:13:48 +00:00
Add snapToGridCenter method to align position coordinates to grid
This commit is contained in:
parent
cedbe1dd6c
commit
1603adf5dd
1 changed files with 31 additions and 0 deletions
|
|
@ -186,6 +186,37 @@ class SparseLocationLogger {
|
|||
}
|
||||
}
|
||||
|
||||
Position snapToGridCenter({
|
||||
required Position position,
|
||||
required double cellSizeDegrees, // e.g. 0.01 ≈ 1.1 km, 0.001 ≈ 110 m
|
||||
}) {
|
||||
Position snappedPosition = position;
|
||||
// Snap latitude
|
||||
final latFloor =
|
||||
(position.latitude / cellSizeDegrees).floor() * cellSizeDegrees;
|
||||
final snappedLat = latFloor + (cellSizeDegrees / 2);
|
||||
|
||||
// Snap longitude
|
||||
final lonFloor =
|
||||
(position.longitude / cellSizeDegrees).floor() * cellSizeDegrees;
|
||||
final snappedLon = lonFloor + (cellSizeDegrees / 2);
|
||||
|
||||
snappedPosition = Position(
|
||||
latitude: snappedLat,
|
||||
longitude: snappedLon,
|
||||
altitude: position.altitude,
|
||||
accuracy: position.accuracy,
|
||||
heading: position.heading,
|
||||
speed: position.speed,
|
||||
speedAccuracy: position.speedAccuracy,
|
||||
altitudeAccuracy: position.altitudeAccuracy,
|
||||
headingAccuracy: position.headingAccuracy,
|
||||
timestamp: position.timestamp,
|
||||
);
|
||||
|
||||
return snappedPosition;
|
||||
}
|
||||
|
||||
Future<String> getGpxFilePath() async => _gpxFile?.path ?? 'Not started';
|
||||
bool isLogging() => _positionStream != null;
|
||||
int getPointCount() => _currentSegment.trkpts.length;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue