geodist

package module
v0.0.0-...-9f2eefb Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2022 License: MIT Imports: 2 Imported by: 0

README

geodist

Go package for calculating latitude and longitude distances.

  • Use shopspring/decimal to avoid floating point precision loss to make the data more accurate.

Features

Install

Run below command in you project

go get github.com/a7103/geodist

How to use

func main() {
	l1 := geodist.Location{Latitude: 43.077363146655784, Longitude: 141.29255316913228}
	l2 := geodist.Location{Latitude: 43.076608521861196, Longitude: 141.30334078044325}

	distance := geodist.HaversineDistance(l1, l2)
	fmt.Printf("l1 and l2 distance is %v mile \n", distance.Mile)
	fmt.Printf("l1 and l2 distance is %v meter \n", distance.Meter)
	fmt.Printf("l1 and l2 distance is %v kilometer \n", distance.Kilometer)

	// Output:
	//
	// l1 and l2 distance is 0.5475360259816643 mile 
	// l1 and l2 distance is 881.1738185340017 meter 
	// l1 and l2 distance is 0.8811738185340017 kilometer 
}

TODO

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddTwoFloat64

func AddTwoFloat64(f1, f2 float64) float64

func DivTwoFloat64

func DivTwoFloat64(f1, f2 float64) float64

func MeterToKilometer

func MeterToKilometer(m float64) float64

func MeterToMile

func MeterToMile(m float64) float64

func MulFloat64

func MulFloat64(float ...float64) float64

func MulTwoFloat64

func MulTwoFloat64(f1, f2 float64) float64

func SubTwoFloat64

func SubTwoFloat64(f1, f2 float64) float64

Types

type Distance

type Distance struct {
	Meter     float64
	Kilometer float64
	Mile      float64
}

func HaversineDistance

func HaversineDistance(l1, l2 Location) Distance

Default return Mile, Meter, Kilometer unit result in Distance struct

type Location

type Location struct {
	Latitude  float64
	Longitude float64
}

Jump to

Keyboard shortcuts

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