2022-05-13 06:09:54 +00:00
|
|
|
|
|
|
|
// 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";
|
|
|
|
}
|
|
|
|
|
2022-05-14 11:58:38 +00:00
|
|
|
public string get_locator(GClue.Location pos) {
|
2022-05-13 06:09:54 +00:00
|
|
|
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";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|