geodist

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2021 License: MIT Imports: 2 Imported by: 13

README

geodist

GoLang package to compute the distance between two geographic latitude, longitude coordinates

Algorithm Comparison

Example

	var newYork = geodist.Coord{Lat: 40.7128, Lon: 74.0060}
	var sanDiego = geodist.Coord{Lat: 32.7157, Lon: 117.1611}
	miles, km, ok := geodist.VincentyDistance(newYork, sanDiego)
	if !ok {
		fmt.Println("Unable to compute Vincenty Distance.")
		return
	}
	fmt.Printf(" [Vincenty] New York to San Diego: %.3f m, %.3f km\n", miles, km)

	var elPaso = geodist.Coord{Lat: 31.7619, Lon: 106.4850}
	var stLouis = geodist.Coord{Lat: 38.6270, Lon: 90.1994}
	miles, km = geodist.HaversineDistance(elPaso, stLouis)
	fmt.Printf("[Haversine] El Paso to St. Louis:  %.3f m, %.3f km\n", miles, km)

Online Calculators

Acknowledgements

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HaversineDistance

func HaversineDistance(p1, p2 Coord) (float64, float64)

HaversineDistance returns the distance (in miles) between two points of

a given longitude and latitude relatively accurately (using a spherical
approximation of the Earth) through the Haversin Distance Formula for
great arc distance on a sphere with accuracy for small distances

point coordinates are supplied in degrees and converted into rad. in the func

http://en.wikipedia.org/wiki/Haversine_formula

func VincentyDistance

func VincentyDistance(p1, p2 Coord) (float64, float64, error)

VincentyDistance computes the distances between two georgaphic coordinates

Args:

p1: the 'starting' point, given in latitude, longitude as a Coord struct

p2: the 'ending' point

Returns:

A 3 element tuple: distance between the 2 points given in (1) miles and (2) kilometers
The 3rd element will return true upon a successful computation or
false if the algorithm fails to converge. -1, -1, false is returned upon failure

Types

type Coord

type Coord struct {
	Lat float64
	Lon float64
}

Coord represents a geographic coordinate

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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