8000 GitHub - sams96/rgeo at v1.1.0
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

sams96/rgeo

Repository files navigation

rgeo

Codecov Release go.dev reference

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, if your coordinates are going to be near specific borders I would advise checking the data beforehand (links to which are in the files). If you want to use your own dataset, check out the datagen folder.

Installation

go get github.com/sams96/rgeo

Usage

Initialise rgeo using rgeo.New, which takes any number of datasets. The included datasets are:

  • Countries110 - Just country information, smallest and lowest detail of the included datasets.
  • Countries10 - The same as above but with more detail.
  • Provinces10 - Includes province information as well as country, so can still be used alone.
  • Cities10 - Just city information, if you want provinces and/or countries as well use one of the above datasets with it. Once initialised you can use ReverseGeocode on the value returned by New, with your coordinates to get the location information. See the Go Docs for more information on usage.
r, err := rgeo.New(Countries110)
if err != nil {
	// Handle error
}

loc, err := r.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
r, err := New(Provinces10, Cities10)
if err != nil {
	// Handle error
}

loc, err := r.ReverseGeocode([]float64{141.35, 43.07})
if err != nil {
	// Handle er
71CA
ror
}

fmt.Println(loc)
// Output: <Location> Sapporo, Hokkaido, Japan (JPN), Asia

Contributing

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

Projects using rgeo

Contributors 4

  •  
  •  
  •  
  •  

Languages

0