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 ¶
- type LatLong
- func (ll LatLong) Decimal() string
- func (ll LatLong) Equal(other LatLong) bool
- func (ll LatLong) MarshalJSON() ([]byte, error)
- func (ll LatLong) MarshalText() ([]byte, error)
- func (ll LatLong) MarshalXMP(key string) map[string]string
- func (ll LatLong) String() string
- func (ll *LatLong) UnmarshalJSON(data []byte) error
- func (ll *LatLong) UnmarshalText(text []byte) error
- func (ll LatLong) Validate() error
- func (ll LatLong) WithAlt(alt float64) LatLong
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
Equal returns true when the positions are the same, with the same altitude, or neither with one
func (LatLong) MarshalJSON ¶
MarshalJSON returns the position as JSON, such as {"lat":52.472697,"long":13.337869}, with alt when there's an altitude
func (LatLong) MarshalText ¶
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 ¶
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 ¶
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 ¶
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 ¶
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)