maidenhead

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2023 License: MIT Imports: 4 Imported by: 1

README

Maidenhead Locator for golang

CircleCI Go Report Card codecov

The Maidenhead Locator System (a.k.a. QTH Locator and IARU Locator) is a geocode system used by amateur radio operators to succinctly describe their geographic coordinates.

This Golang library compresses and decompresses (latitude, longitude) coordinates to and from a Maidenhead locator.

Installation

go get -u github.com/logocomune/maidenhead

Usage

package main

import (
	"fmt"
	"github.com/logocomune/maidenhead"
)

func main() {
	latitude := 43.723073
	longitude := 10.396637

	locator, _ := maidenhead.Locator(latitude, longitude, maidenhead.FieldPrecision)
	fmt.Println("Locator with field precision:", locator)
	locator, _ = maidenhead.Locator(latitude, longitude, maidenhead.SquarePrecision)
	fmt.Println("Locator with square precision:", locator)
	locator, err := maidenhead.Locator(latitude, longitude, maidenhead.SubSquarePrecision)
	fmt.Println("Locator with sub square precision:", locator, err)
	locator, _ = maidenhead.Locator(latitude, longitude, maidenhead.ExtendedSquarePrecision)
	fmt.Println("Locator with extended square precision:", locator)
	locator, _ = maidenhead.Locator(latitude, longitude, maidenhead.SubExtendedSquarePrecision)
	fmt.Println("Locator with sub extended square precision:", locator)

	lat, lng, _ := maidenhead.GridCenter("JN53er73OM")
	fmt.Printf("Grid center of %s is lat: %f and lng: %f\n", "JN53er73OM", lat, lng)

	square, _ := maidenhead.Square("JN53er73OM")
	fmt.Printf("Square coordinates of %s are %+v\n", "JN53er73OM", square)
}

Documentation

Index

Constants

View Source
const (
	FieldPrecision             = 2
	SquarePrecision            = 4
	SubSquarePrecision         = 6
	ExtendedSquarePrecision    = 8
	SubExtendedSquarePrecision = 10
)

Variables

This section is empty.

Functions

func GridCenter

func GridCenter(locator string) (float64, float64, error)

GridCenter returns the center of the square grid

func Locator

func Locator(lat, lng float64, precision int) (string, error)

Locator returns the Maidenhead locator for the given latitude and longitude and requested precision.

Types

type Coordinate

type Coordinate struct {
	Lat float64
	Lng float64
}

type SquareCoordinate

type SquareCoordinate struct {
	Center      Coordinate
	TopLeft     Coordinate
	TopRight    Coordinate
	BottomLeft  Coordinate
	BottomRight Coordinate
}

func Square

func Square(locator string) (SquareCoordinate, error)

Square returns the coordinates of the vertices of the square grid

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL