diff --git a/src/maidenhead.vala b/src/maidenhead.vala new file mode 100644 index 0000000..dac7ce6 --- /dev/null +++ b/src/maidenhead.vala @@ -0,0 +1,38 @@ + +// Ported from: +// https://metacpan.org/release/MEH/Ham-Locator-0.1000/source/lib/Ham/Locator.pm + +namespace Hamlocator { + public class LocationToMaidenhead : Object { + private string l2m; + + public LocationToMaidenhead() { + this.l2m = "abcdefghijklmnopqrstuvwxyz"; + } + + public string get_current_location (GClue.Location pos) { + double lat = pos.latitude + 90; + double lon = pos.longitude + 180; + + // Field + double lat1 = (lat / 10) + 0.0000001; + double lon1 = (lon / 20) + 0.0000001; + + string loc1 = @"$(this.l2m[Math.lround(Math.floor(lon1))])$(this.l2m[Math.lround(Math.floor(lat1))])".up(); + + // Square + double lat2 = 10 * (lat1 - Math.floor(lat1)); + double lon2 = 10 * (lon1 - Math.floor(lon1)); + + string loc2 = @"$(Math.lround(Math.floor(lon2)))$(Math.lround(Math.floor(lat2)))"; + + // Subsquare + double lat3 = 24 * (lat1 - Math.floor(lat1)); + double lon3 = 24 * (lon1 - Math.floor(lon1)); + + string loc3 = @"$(this.l2m[Math.lround(Math.floor(lon3))])$(this.l2m[Math.lround(Math.floor(lat3))])"; + + return @"$loc1$loc2$loc3"; + } + } +} diff --git a/src/meson.build b/src/meson.build index ef99c6c..b17ea3c 100644 --- a/src/meson.build +++ b/src/meson.build @@ -2,7 +2,8 @@ hamlocator_sources = [ 'main.vala', 'window.vala', 'application.vala', - 'location.vala' + 'location.vala', + 'maidenhead.vala' ] hamlocator_deps = [ @@ -18,6 +19,8 @@ hamlocator_sources += gnome.compile_resources('hamlocator-resources', ) executable('hamlocator', hamlocator_sources, - vala_args: '--target-glib=2.50 --pkg=gio-2.0', dependencies: hamlocator_deps, + vala_args: '--target-glib=2.50 --pkg=gio-2.0', + dependencies: hamlocator_deps, + link_args: '-lm', install: true, )