diff options
| author | mirror <mirror@localhost> | 2026-11-22 08:41:00 +0900 |
|---|---|---|
| committer | mirror <mirror@localhost> | 2026-11-22 08:41:00 +0900 |
| commit | 449d8b74bd6d9dae98a07254cdfad677b920e7b0 (patch) | |
| tree | c131c3528c4d517f56e19b854a7453fedb097d40 /lib/geo/uri.dart | |
| download | aves-src-master.tar.gz aves-src-master.zip | |
Diffstat (limited to 'lib/geo/uri.dart')
| -rw-r--r-- | lib/geo/uri.dart | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/geo/uri.dart b/lib/geo/uri.dart new file mode 100644 index 0000000..3241d0a --- /dev/null +++ b/lib/geo/uri.dart @@ -0,0 +1,37 @@ +import 'package:aves/utils/math_utils.dart'; +import 'package:latlong2/latlong.dart'; + +// e.g. `geo:44.4361283,26.1027248?z=4.0(Bucharest)` +// cf https://en.wikipedia.org/wiki/Geo_URI_scheme +// cf https://developer.android.com/guide/components/intents-common#ViewMap +(LatLng, double?)? parseGeoUri(String? uri) { + if (uri != null) { + final geoUri = Uri.tryParse(uri); + if (geoUri != null) { + final coordinates = geoUri.path.split(','); + if (coordinates.length == 2) { + final lat = double.tryParse(coordinates[0]); + final lon = double.tryParse(coordinates[1]); + if (lat != null && lon != null) { + double? zoom; + final zoomString = geoUri.queryParameters['z']; + if (zoomString != null) { + zoom = double.tryParse(zoomString); + } + return (LatLng(lat, lon), zoom); + } + } + } + } + return null; +} + +String toGeoUri(LatLng latLng, {double? zoom}) { + final latitude = roundToPrecision(latLng.latitude, decimals: 6); + final longitude = roundToPrecision(latLng.longitude, decimals: 6); + var uri = 'geo:$latitude,$longitude?q=$latitude,$longitude'; + if (zoom != null) { + uri += '&z=$zoom'; + } + return uri; +} |
