revgeo

package module
v0.0.0-...-fa2134a Latest Latest
Warning

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

Go to latest
Published: May 11, 2020 License: MIT Imports: 13 Imported by: 0

README

Package revgeo provides a reverse geocoding capability. Latitude and longitude to ISO country code

Certain purpose:

  • determine in which country is Lat Lng coordinate
  • very fast processing thru GeoJSON polygons

func (*Decoder) Geocode

Geocode gets lat and lng, returns country ISO code

  func (d *Decoder) Geocode(lat float64, lng float64) (string, error)

Example

package main

import ("github.com/filipkroca/revgeo"
"fmt"
"log"
)

func main() {
  decoder := revgeo.Decoder{}

  var lat float64
  var lng float64

  lat = 48.75181328781114
  lng = 16.234285804999985
  country, err := decoder.Geocode(lng, lat)

  if err != nil {
    log.Panicln(err)
  }

  fmt.Println(country)
  // Output:
  // CZE
}

Performance

BenchmarkDecode_Geocode-8   300   5265501 ns/op      49 B/op      2 allocs/op

Documentation

Overview

Package revgeo provides a reverse geocoding capability. Latitude and longitude to ISO country code. This package uses GeoJSON polygons. DATASET source: https://datahub.io/core/geo-countries#data-cli

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

Types

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder holds gemetry in memory and provides method Geocode()

Example (Geocode)
decoder := Decoder{}

var lat float64
var lng float64

lat = 48.75181328781114
lng = 16.234285804999985
country, err := decoder.Geocode(lng, lat)

if err != nil {
	log.Panicln(err)
}

fmt.Println(country)
Output:
CZE

func (*Decoder) Geocode

func (d *Decoder) Geocode(lat float64, lng float64) (string, error)

Geocode gets lat and lng, returns country ISO code

Jump to

Keyboard shortcuts

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