geo

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 10 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package geo defines a position on the Earth, as a latitude and longitude in decimal degrees, and optionally an altitude in metres, which is text in degrees, minutes and seconds, such as 52°28'21.71"N 13°20'16.33"E 91.5m, or decimal degrees, such as "52.472697,13.337869,91.5", as in a geo URI (RFC 5870), and JSON such as {"lat":52.472697,"long":13.337869,"alt":91.5}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LatLong

type LatLong struct {
	Lat  float64  `json:"lat"`
	Long float64  `json:"long"`
	Alt  *float64 `json:"alt,omitempty"`
}

LatLong is a position, as a latitude and longitude in decimal degrees, which are negative in the southern and western hemispheres, and an altitude in metres above sea level, which is negative below it, or nil when it isn't known

func New

func New(lat, long float64) (LatLong, error)

New returns a position without an altitude, or an error when the latitude isn't between -90 and 90, or the longitude between -180 and 180

func Parse

func Parse(text string) (LatLong, error)

Parse returns a position from text, which is the latitude, longitude and optionally the altitude, separated by commas, in that order, as in ISO 6709 and a geo URI (RFC 5870), such as "52.472697,13.337869" or "52.472697,13.337869,91.5", with or without spaces, or in degrees, minutes and seconds, such as 52°28'21.71"N 13°20'16.33"E 91.5m (see DMS)

func ParseISO6709

func ParseISO6709(text string) (LatLong, error)

ParseISO6709 returns a position from text in ISO 6709, in decimal degrees, such as +52.4158+013.5896+035.667/, whose altitude, in metres, is optional, or an error when it isn't one, or it isn't on the Earth

func (LatLong) Decimal

func (ll LatLong) Decimal() string

Decimal returns the position in decimal degrees, such as "52.472697,13.337869", or "52.472697,13.337869,91.5" with an altitude. The latitude is first, as in ISO 6709 and a geo URI (RFC 5870), unlike GeoJSON, whose longitude is first; text in degrees, minutes and seconds (see String) has hemispheres, so isn't ambiguous.

func (LatLong) Equal

func (ll LatLong) Equal(other LatLong) bool

Equal returns true when the positions are the same, with the same altitude, or neither with one

func (LatLong) MarshalJSON

func (ll LatLong) MarshalJSON() ([]byte, error)

MarshalJSON returns the position as JSON, such as {"lat":52.472697,"long":13.337869}, with alt when there's an altitude

func (LatLong) MarshalText

func (ll LatLong) MarshalText() ([]byte, error)

MarshalText returns the position in degrees, minutes and seconds, such as 52°28'21.71"N 13°20'16.33"E, with the altitude when there is one, such as 52°28'21.71"N 13°20'16.33"E 91.5m, whose seconds are rounded to a hundredth (see String)

func (LatLong) MarshalXMP

func (ll LatLong) MarshalXMP(key string) map[string]string

MarshalXMP returns the position as the GPS properties of the exif schema of XMP, when the key is in the exif namespace, such as exif:GPSPosition: exif:GPSLatitude and exif:GPSLongitude, as degrees and minutes, with their hemisphere, such as "53,14.053167N", and exif:GPSAltitude, a rational in metres, and exif:GPSAltitudeRef, which is 1 below sea level, when there's an altitude. It returns none for a key in another namespace, such as dc:coverage, which is written as its text (see String).

func (LatLong) String

func (ll LatLong) String() string

String returns the position in degrees, minutes and seconds, such as 52°28'21.71"N 13°20'16.33"E, with the altitude in metres when there is one, such as 52°28'21.71"N 13°20'16.33"E 91.5m. The seconds are rounded to a hundredth, which is about 30cm, and the altitude to a centimetre.

func (*LatLong) UnmarshalJSON

func (ll *LatLong) UnmarshalJSON(data []byte) error

UnmarshalJSON sets the position from JSON, which is an object with both lat and long, and optionally alt, such as {"lat":52.472697,"long":13.337869,"alt":91.5}, or a string of its text, such as "52.472697,13.337869,91.5"

func (*LatLong) UnmarshalText

func (ll *LatLong) UnmarshalText(text []byte) error

UnmarshalText sets the position from text, in degrees, minutes and seconds, such as 52°28'21.71"N 13°20'16.33"E, or decimal degrees, such as "52.472697,13.337869" (see Parse)

func (LatLong) Validate

func (ll LatLong) Validate() error

Validate returns an error when the latitude isn't between -90 and 90, or the longitude between -180 and 180, or either, or the altitude, isn't a finite number

func (LatLong) WithAlt

func (ll LatLong) WithAlt(alt float64) LatLong

WithAlt returns the position with an altitude, in metres above sea level, which is negative below it

Jump to

Keyboard shortcuts

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