Files
meshcore-open/lib/utils/location_grid.dart
T
zjs81 bc14de586f Add opt-in network map uploads and online map view
- Opt-in upload of header-only packet records and repeater/room server
  adverts to map.meshcoreopen.org about once a minute; payloads, channel
  and DM hashes and transport codes are stripped on the phone, locations
  snapped to a ~2 km grid, install ID rotates daily
- One-time opt-in dialog on first radio connection; toggle and status in
  App settings
- Local / Online / Both switch on the map screen with online repeater
  hexagons, links, add-to-contacts and manage
- Node purchase banner on the connect screen (affiliate link, disclosed)
- Privacy policy and network map documentation
- Translations for all locales
2026-10-11 21:54:16 -07:00

23 lines
946 B
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'dart:math' as math;
/// Grid spacing in degrees (~2.2 km north–south). Shared with the network map
/// server, which rejects any uploaded coordinate that is not a grid center.
const double locationGridSize = 0.02;
/// Snaps a coordinate to the center of its network-map grid cell.
///
/// Every coordinate that leaves the phone goes through this. The algorithm is
/// fixed by the network map API contract; snapping a center returns the same
/// center.
({double lat, double lon}) snapToLocationGrid(double lat, double lon) {
const g = locationGridSize;
final latIdx = (lat / g).floor();
final latC = ((latIdx + 0.5) * g).clamp(-89.99, 89.99).toDouble();
final step = g / math.max(math.cos(latC * math.pi / 180), 0.1);
final lonIdx = ((lon + 180) / step).floor();
final lonC = -180 + (lonIdx + 0.5) * step;
return (lat: _round6(latC), lon: _round6(lonC));
}
double _round6(double value) => (value * 1e6).round() / 1e6;