Git Product home page Git Product logo

chtozaslova's Introduction

ChtoZaSlova

Go library

This is the ChtoZaSlova Go library, command-line tool, and API server.

It converts between latitude/longitude coordinates and what3words addresses.

ChtoZaSlova is free and open source software published under the Creative Commons CC0 license. Please copy and distribute widely.

Using the Go library

    import "chtozaslova/chtozaslova"

    ...

    words, err := chtozaslova.LatLon2Words(37.234332, -115.806657)
    fmt.Println(words)
    lat, lon, err := chtozaslova.Words2LatLon("joyful.nail.harmonica")
    fmt.Printf("%.6f %.6f\n", lat, lon)

See example/main.go for an example.

LatLon2Words and Words2LatLon are the only functions considered part of the API, but you are welcome to use the other exported functions if you find them useful.

Using the command-line tool

The tool in cmd/chtozaslova/ is a command-line interface for converting between latitude/longitude coordinates and what3words addresses.

Help text is as follows:

usage: chtozaslova [-i] [INPUT...]

Options:
  -i    read from stdin

If not -i, you should specify at least one INPUT in the form lat,lon or words. It is perfectly acceptable to mix lat,lon and word inputs in a single invocation.

Examples:
    chtozaslova -i < words.txt
    chtozaslova joyful.nail.harmonica
    chtozaslova 37.234332,-115.806657

Output is of the form "INPUT[tab]OUTPUT" with one line per INPUT, where OUTPUT will be either the converted INPUT, or an error message.

Using the API server

The tool in cmd/chtozaslovad/ is an HTTP server that provides a HTTP API for converting between latitude/longitude coordinates and what3words addresses. It listens on port 8081.

Parameters are passed in the HTTP query string and responses are formatted as JSON.

Make requests like:

$ curl http://localhost:8081/api/convert-to-coordinates?words=joyful.nail.harmonica
{"words":"joyful.nail.harmonica","language":"en","coordinates":{"lat":37.234328,"lon":-115.806657}}
$ curl http://localhost:8081/api/convert-to-3wa?coordinates=37.234328,-115.806657
{"words":"joyful.nail.harmonica","language":"en","coordinates":{"lat":37.234328,"lon":-115.806657}}

In the event of an error, the error key will exist in the returned JSON hash, and the value of this key will be an error message:

$ curl http://localhost:8081/api/convert-to-coordinates?words=errormessage
{"error":"Error decoding words"}

Development

The files of the library are in *.go in the root directory.

For the command line application, see cmd/chtozaslova/main.go.

For the API server, see cmd/chtozaslovad/main.go.

chtozaslova's People

Contributors

chtozaslova 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.