haversine

package module
v0.0.0-...-808ab04 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2015 License: MIT Imports: 1 Imported by: 71

README

Build Status

Haversine

Package haversine is a Go library which implements the haversine formula. The haversine formula gives great-circle distances between two points on a sphere from their longitudes and latitudes. The sphere in this case is the surface of the Earth.

Earth great circle

The dotted yellow line is an arc of a great circle. It gives the shortest distance between the two yellow points. Image courtesy USGS.

Installation

go get github.com/umahmood/haversine

cd $GOPATH/src/github.com/umahmood/haversine/

go test -v ./...

Usage

The below example shows how to calculate the shortest path between two coordinates on the surface of the Earth.

package main

import (
    "fmt"

    "github.com/umahmood/haversine"
)

func main() {
    oxford := haversine.Coord{Lat: 51.45, Lon: 1.15}  // Oxford, UK
    turin  := haversine.Coord{Lat: 45.04, Lon: 7.42}  // Turin, Italy
    mi, km := haversine.Distance(oxford, turin)
    fmt.Println("Miles:", mi, "Kilometers:", km)
}

Documenation

http://godoc.org/github.com/umahmood/haversine

References

License

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

Documentation

Overview

Package haversine implements the haversine formula.

The below example shows how to calculate the shortest path between two coordinates on the surface of the Earth.

package main

import (
    "fmt"

    "github.com/umahmood/haversine"
)

func main() {
    oxford := haversine.Coord{Lat: 51.45, Lon: 1.15}  // Oxford, UK
    turin  := haversine.Coord{Lat: 45.04, Lon: 7.42}  // Turin, Italy

    mi, km := haversine.Distance(oxford, turin)

    fmt.Println("Miles:", mi, "Kilometers:", km)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Distance

func Distance(p, q Coord) (mi, km float64)

Distance calculates the shortest path between two coordinates on the surface of the Earth. This function returns two units of measure, the first is the distance in miles, the second is the distance in kilometers.

Types

type Coord

type Coord struct {
	Lat float64
	Lon float64
}

Coord represents a geographic coordinate.

Jump to

Keyboard shortcuts

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