Coder Social home page Coder Social logo

timezonelookup's Introduction

Timezone lookup

Is a timezone lookup API for GPS Coordinates to Timezone based on GeoJSON Polygon and Multipolygon files.

Source Data

Source files can be obtained at https://github.com/evansiroky/timezone-boundary-builder

Performance

Performance is significantly improved between release v1 and release v2 due to the underlying data structure. Timezone database is approxiamtely 50mb in size and lookups range between 50 - 200 microseconds. Recent verion uses an RTree as well as a Memory mapped timezone database for reduced latency and increased throughput.

[]Benchmarks still need to be written.

Authors

Appreciate all who have contributed with Pull Requests and Issues. We eagerly welcome suggestions and PRs.

Rtree source design by Josh Backer tidwall

Example

Build program

go build -o timezone cmd/main.go 

Download datasource and build timezone database ~50mb

./timezone -build

Test query for San Fransisco, United States (Etc/GMT+8)

./timezone -search -lat=37.7749 -lng=-122.4194

Release V2.0 and forward

Based on custom backing that loads data as memory mapped data.

package main

import (
	"fmt"

	timezone "github.com/evanoberholster/[email protected]"
)

func main() {
	var tzc timezone.Timezonecache
	f, err := os.Open("timzone.data")
	if err != nil {
		return timezone.Result{}, err
	}
	defer f.Close()
	if err = tzc.Load(f); err != nil {
		return timezone.Result{}, err
	}
	defer tzc.Close()

	lat := 37.7749
	lng := -122.4194

	result := tzc.Search(lat, lng)
	fmt.Println(result)
}

Release V1.0 and prior

Based on JSON, MsgPack, Protobuf or Cap'n'Proto encodings with boltDB backend

Intructions for V1.0

  1. Download data from: https://github.com/evansiroky/timezone-boundary-builder/releases
  2. go get github.com/evanoberholster/[email protected]
  3. go build github.com/evanoberholster/timezoneLookup/cmd/timezone.go
  4. timezone -json "jsonfilename" -db=timezone -type=(memory or boltdb)
  5. go run example.go
package main
import (
	"fmt"
	timezone "github.com/evanoberholster/[email protected]"
)
var tz timezone.TimezoneInterface

func main() {
	tz, err := timezone.LoadTimezones(timezone.Config{
		DatabaseType:"boltdb", // memory or boltdb
		DatabaseName:"timezone", // Name without suffix
		Snappy: true,
		Encoding: "msgpack", // json or msgpack
	})
	if err != nil {
		fmt.Println(err)
	}

	res, err := tz.Query(timezone.Coord{
			Lat: 5.261417, Lon: -3.925778,})
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println("Query Result: ", res)

	tz.Close()
}

timezonelookup's People

Contributors

bnfinet avatar dhduvall avatar evanoberholster avatar tgulacsi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.