rgeo

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2020 License: LGPL-3.0 Imports: 3 Imported by: 5

README

rgeo

go.dev reference Release

Package rgeo is a fast, simple solution for local reverse geocoding

Rather than relying on external software or online APIs, rgeo packages all of the data it needs in your binary. This means it will only ever work down to the level of cities (though currently just countries), but if that's all you need then this is the library for you.

rgeo uses data from naturalearthdata.com.

Installation

go get github.com/sams96/rgeo

Usage

loc, err := rgeo.ReverseGeocode([]float64{0, 52})
if err != nil {
	// Handle error
}

fmt.Printf("%s\n", loc.Country)
fmt.Printf("%s\n", loc.CountryLong)
fmt.Printf("%s\n", loc.CountryCode2)
fmt.Printf("%s\n", loc.CountryCode3)
fmt.Printf("%s\n", loc.Continent)
fmt.Printf("%s\n", loc.Region)
fmt.Printf("%s\n", loc.SubRegion)

// Output: United Kingdom
// United Kingdom of Great Britain and Northern Ireland
// GB
// GBR
// Europe
// Europe
// Northern Europe

Contributing

Contributions are welcome, I haven't got any guidelines or anything so maybe just make an issue first.

Documentation

Overview

Package rgeo is a fast, simple solution for local reverse geocoding

Rather than relying on external software or online APIs, rgeo packages all of the data it needs in your binary. This means it will only ever work down to the level of cities (though currently just countries), but if that's all you need then this is the library for you.

rgeo uses data from https://naturalearthdata.com.

Installation

go get github.com/sams96/rgeo

Contributing

Contributions are welcome, I haven't got any guidelines or anything so maybe just make an issue first.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Location

type Location struct {
	// Commonly used country name
	Country string

	// Formal name of country
	CountryLong string

	// Two and three letter ISO 3166 codes
	CountryCode2 string
	CountryCode3 string

	Continent string
	Region    string
	SubRegion string
}

Location is the return type for ReverseGeocode

func ReverseGeocode

func ReverseGeocode(loc geom.Coord) (Location, error)

ReverseGeocode returns the country in which the given coordinate is located

The input is a geom.Coord, which is just a []float64 with the longitude in the zeroth position and the latitude in the first position. (i.e. []float64{lon, lat})

When run without a type rgeo it re-creates the polygons every time

Example
loc, err := ReverseGeocode([]float64{0, 52})
if err != nil {
	// Handle error
}

fmt.Printf("%s\n", loc.Country)
fmt.Printf("%s\n", loc.CountryLong)
fmt.Printf("%s\n", loc.CountryCode2)
fmt.Printf("%s\n", loc.CountryCode3)
fmt.Printf("%s\n", loc.Continent)
fmt.Printf("%s\n", loc.Region)
fmt.Printf("%s\n", loc.SubRegion)
Output:

United Kingdom
United Kingdom of Great Britain and Northern Ireland
GB
GBR
Europe
Europe
Northern Europe

func (Location) String

func (l Location) String() string

String method for type Location

Directories

Path Synopsis
This program is converts geojson files into go files containing structs that can be read by rgeo.
This program is converts geojson files into go files containing structs that can be read by rgeo.

Jump to

Keyboard shortcuts

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