Skip to content

Haversine is a Go package that finds the shortest great circle route between to points on the earth.

License

Notifications You must be signed in to change notification settings

FATHOM5CORP/haversine

 
 

Repository files navigation

GoDoc Reference Build Status Go Report Card Coverage Status

Haversine

Package haversine provides the great circle distance between two points on the surface of the earth. Points are identified by latitude and longitude, and distance results can be returned in nautical miles, statute miles, or kilometers.
Earth great circle

The curvature of the earth dictates that the shortest distance between two points cannot be a straight line between the points. The Haversine formula provides an approximation for the shortest great circle route over the surface of earth that connects the two points. In this figure the dotted yellow line is the arc of a great circle. Image courtesy USGS.

Installation

go get github.com/FATHOM5/haversine

Usage

The example below shows how far I'd have to walk in my boots to go visit my co-founder.

package main

import (
    "fmt"

    "github.com/FATHOM5/haversine"
)

func main() {
    austin := haversine.Coord{ // Austin, Texas
        Lat: 30.2672,
        Lon: -97.7431,
    }
    paloAlto := haversine.Coord{ // Palo Alto, California
        Lat: 37.4419,
        Lon: -122.1430,
    }

    nm := haversine.Distance(austin, paloAlto)

    fmt.Printf("%.1f miles is a long walk to Silicon Valley.\n", nm)

// Output: 1286.1 miles is a long walk to Silicon Valley.
}

Documenation

References

License

See LICENSE for rights and limitations (MIT).

About

Haversine is a Go package that finds the shortest great circle route between to points on the earth.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%