Giter Site home page Giter Site logo

kwahome / go-haversine Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 0.0 12 KB

The Haversine formula determines the great-circle distance between two points on a sphere given their latitudes and longitudes.

License: MIT License

Shell 1.91% Go 98.09%
circle-distance haversine-distance haversine golang go

go-haversine's Introduction

go-haversine

The Haversine formula determines the great-circle distance between two points on a sphere given their latitudes and longitudes. Important in navigation, it is a special case of a more general formula in spherical trigonometry, the law of Haversines, that relates the sides and angles of spherical triangles.

Installation

go get https://github.com/kwahome/go-haversine

Usage

Below is an example showing how to calculate the shortest path between two coordinates on the surface of the Earth.

package main

import (
	"fmt"
	"github.com/kwahome/go-haversine/pkg/haversine"
)

func main() {
	nairobi := haversine.Coordinate{
		Latitude: 1.2921,
		Longitude: 36.8219,
	}
	mombasa := haversine.Coordinate{
		Latitude: 4.0435,
		Longitude: 39.6682,
	}

	units := haversine.M
	distance := nairobi.DistanceTo(mombasa, units)
	fmt.Println("Distance from Nairobi =", nairobi, "to Mombasa =", mombasa, "in", units, "is", distance)

	units = haversine.KM
	distance = nairobi.DistanceTo(mombasa, units)
	fmt.Println("Distance from Nairobi =", nairobi, "to Mombasa =", mombasa, "in", units, "is", distance)

	units = haversine.MI
	distance = nairobi.DistanceTo(mombasa, units)
	fmt.Println("Distance from Nairobi =", nairobi, "to Mombasa =", mombasa, "in", units, "is", distance)
}
Distance from Nairobi = {latitude=1.2921, longitude=36.8219} to Mombasa = {latitude=4.0435, longitude=39.6682} in meters is 439923.26193980715
Distance from Nairobi = {latitude=1.2921, longitude=36.8219} to Mombasa = {latitude=4.0435, longitude=39.6682} in kilometers is 439.92326193980716
Distance from Nairobi = {latitude=1.2921, longitude=36.8219} to Mombasa = {latitude=4.0435, longitude=39.6682} in miles is 273.3034485571742

Development

Find the entire code in the repository:

https://github.com/kwahome/go-haversine

Use convenience scripts in ./bin to run tests and format code.

Tests:

./bin/unit_test.sh

Code formatting:

./bin/code_format.sh

Docs

https://godoc.org/github.com/kwahome/go-haversine

License

See the LICENSE file for license rights and limitations (MIT).

go-haversine's People

Contributors

kwahome avatar

Stargazers

 avatar

Watchers

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