geodist

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2020 License: MIT Imports: 2 Imported by: 4

README

geodist

GoDoc Build Status

Implementation of the Haversine and Vincenty methods in Go for calculating geographical distances between points on the surface of the Earth.

Installation

go get github.com/asmarques/geodist

Usage

package main

import (
	"fmt"
	"github.com/asmarques/geodist"
)

func main() {
	lis := geodist.Point{38.781311, -9.135918}
	sfo := geodist.Point{37.618817, -122.375427}

	d := geodist.HaversineDistance(lis, sfo)
	fmt.Printf("Haversine: %.2f km\n", d)

	d, err := geodist.VincentyDistance(lis, sfo)
	if err != nil {
		fmt.Printf("Failed to converge: %v", err)
	}

	fmt.Printf("Vincenty: %.6f km\n", d)
}

License

MIT

Documentation

Overview

Package geodist implements the Haversine and Vincenty methods for calculating geographical distances between points on the surface of the Earth.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HaversineDistance

func HaversineDistance(p1 Point, p2 Point) float64

HaversineDistance returns the geographical distance in km between the points p1 and p2 using the Haversine formula. The surface of the Earth is approximated by a sphere with a radius of 6371 km.

func VincentyDistance

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

VincentyDistance returns the geographical distance in km between the points p1 and p2 using Vincenty's inverse formula. The surface of the Earth is approximated by the WGS-84 ellipsoid. This method may fail to converge for nearly antipodal points.

Types

type Point

type Point struct {
	// Latitude of the point in degrees
	Lat float64
	// Longitude of the point in degrees
	Long float64
}

Point represents the coordinates of a given point on Earth

Jump to

Keyboard shortcuts

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