func main() {
	lat1, lon1 := 37.619002, -122.374843
	lon2, lat2 := 33.942536, -118.408074
	// To
	{
		geo1 := ellipsoid.Init("WGS84", ellipsoid.Degrees, ellipsoid.Meter, ellipsoid.LongitudeIsSymmetric, ellipsoid.BearingIsSymmetric)
		dist, bear := geo1.To(lat1, lon1, lon2, lat2)
		fmt.Printf("1 dist = %v bear = %v\n", dist, bear)
	}
	{
		geo1 := ellipsoid.Init("AIRY", ellipsoid.Degrees, ellipsoid.Meter, ellipsoid.LongitudeIsSymmetric, ellipsoid.BearingIsSymmetric)
		dist, bear := geo1.To(lat1, lon1, lon2, lat2)
		fmt.Printf("2 dist = %v bear = %v\n", dist, bear)
	}
	{
		geo1 := ellipsoid.Init("AIRY", ellipsoid.Radians, ellipsoid.Meter, ellipsoid.LongitudeIsSymmetric, ellipsoid.BearingNotSymmetric)
		dist, bear := geo1.To(lat1, lon1, lon2, lat2)
		fmt.Printf("3 dist = %v bear = %v\n", dist, bear)
	}
	{
		geo1 := ellipsoid.Init("AIRY", ellipsoid.Radians, ellipsoid.Meter, ellipsoid.LongitudeIsSymmetric, ellipsoid.BearingIsSymmetric)
		dist, bear := geo1.To(lat1, lon1, lon2, lat2)
		fmt.Printf("4 dist = %v bear = %v\n", dist, bear)
	}
	{
		geo1 := ellipsoid.Init("AIRY", ellipsoid.Degrees, ellipsoid.Kilometer, ellipsoid.LongitudeIsSymmetric, ellipsoid.BearingIsSymmetric)
		dist, bear := geo1.To(lat1, lon1, lon2, lat2)
		fmt.Printf("5 dist = %v bear = %v\n", dist, bear)
	}
	{
		geo1 := ellipsoid.Init("AIRY", ellipsoid.Degrees, ellipsoid.Foot, ellipsoid.LongitudeIsSymmetric, ellipsoid.BearingIsSymmetric)
		dist, bear := geo1.To(lat1, lon1, lon2, lat2)
		fmt.Printf("6 dist = %v bear = %v\n", dist, bear)
	}
	// At
	{
		geo1 := ellipsoid.Init("AIRY", ellipsoid.Degrees, ellipsoid.Foot, ellipsoid.LongitudeIsSymmetric, ellipsoid.BearingIsSymmetric)
		lat2, lon2 := geo1.At(lat1, lon1, 2000.0, 45.0)
		fmt.Printf("7 lat  = %v lon = %v\n", lat2, lon2)
	}
	{
		geo1 := ellipsoid.Init("AIRY", ellipsoid.Degrees, ellipsoid.Meter, ellipsoid.LongitudeIsSymmetric, ellipsoid.BearingIsSymmetric)
		lat2, lon2 := geo1.At(lat1, lon1, 2000.0, 45.0)
		fmt.Printf("8 lat  = %v lon = %v\n", lat2, lon2)
	}
	{
		geo1 := ellipsoid.Init("AIRY", ellipsoid.Degrees, ellipsoid.Meter, ellipsoid.LongitudeIsSymmetric, ellipsoid.BearingIsSymmetric)
		lat2, lon2 := geo1.At(90.0, 90.0, 1000.0, 90.0)
		fmt.Printf("9 lat  = %v lon = %v\n", lat2, lon2)
	}
	// To
	{
		geo1 := ellipsoid.Init("WGS84", ellipsoid.Degrees, ellipsoid.Nm, ellipsoid.LongitudeIsSymmetric, ellipsoid.BearingIsSymmetric)
		lat3, lon3 := 73.06, 19.11 // Mumbai
		lat4, lon4 := 4.89, 52.37  // Amsterdam
		dist, bear := geo1.To(lat3, lon3, lat4, lon4)
		fmt.Printf("10 dist  = %v bear = %v\n", dist, bear)
	}
}
func main() {
	lat1, lon1 := 37.619002, -122.374843 //SFO
	lat2, lon2 := 33.942536, -118.408074 //LAX

	// Create Ellipsoid object with WGS84-ellipsoid,
	// angle units are degrees, distance units are meter.
	geo1 := ellipsoid.Init("WGS84", ellipsoid.Degrees, ellipsoid.Meter, ellipsoid.LongitudeIsSymmetric, ellipsoid.BearingIsSymmetric)

	// Calculate the distance and bearing from SFO to LAX.
	distance, bearing := geo1.To(lat1, lon1, lat2, lon2)
	fmt.Printf("----- Testing To\n")
	fmt.Printf("Distance = %v Bearing = %v\n", distance, bearing)

	// Calculate where you are when going from SFO in
	// direction 45.0 deg. for 20000 meters.
	fmt.Printf("----- Testing At\n")
	lat3, lon3 := geo1.At(lat1, lon1, 20000.0, 45.0)
	fmt.Printf("lat3 = %v lon3 = %v\n", lat3, lon3)

	// Convert Lat-Lon-Alt to ECEF.
	lat4, lon4, alt4 := 39.197807, -77.108574, 55.0 // Some location near Baltimore
	// that the author of the Perl module geo-ecef used. I reused the coords of the tests.
	fmt.Printf("----- Testing ToECEF\n")
	x, y, z := geo1.ToECEF(lat4, lon4, alt4)
	fmt.Printf("x = %v \ny = %v \nz = %v\n", x, y, z)

	// Convert ECEF to Lat-Lon-Alt.
	x1, y1, z1 := 1.1042590709397183e+06, -4.824765955871677e+06, 4.0093940281868847e+06
	fmt.Printf("----- Testing ToLLA\n")
	lat5, lon5, alt5 := geo1.ToLLA(x1, y1, z1)
	fmt.Printf("lat5 = %v lon5 = %v alt3 = %v\n", lat5, lon5, alt5)

	// Displacement. Use only for small distances!
	l1, l2 := 41.978744444444, 272.096858333333
	m1, m2 := 42.005419444444, 272.073286111111
	dx, dy := geo1.Displacement(l1, l2, m1, m2)
	fmt.Printf("----- Testing Displacement\n")
	fmt.Printf("x,y=      %v %v\n", dx, dy)
	fmt.Printf("Expected: -1952.8108885261 2963.14446772882\n")

	fmt.Printf("----- Done ---\n")
}
Example #3
0
package openflights

import (
	"math"
	"strconv"
	"strings"

	"github.com/StefanSchroeder/Golang-Ellipsoid/ellipsoid"

	"google.golang.org/grpc"
	"google.golang.org/grpc/codes"
)

var (
	geo = ellipsoid.Init("WGS84", ellipsoid.Degrees, ellipsoid.Mile, ellipsoid.LongitudeIsSymmetric, ellipsoid.BearingIsSymmetric)
)

func getAirportByKey(m map[string]*Airport, key string) (*Airport, error) {
	airport, ok := m[strings.ToLower(key)]
	if !ok {
		return nil, grpc.Errorf(codes.NotFound, key)
	}
	return airport, nil
}

func getAirlineByKey(m map[string]*Airline, key string) (*Airline, error) {
	airline, ok := m[strings.ToLower(key)]
	if !ok {
		return nil, grpc.Errorf(codes.NotFound, key)
	}
	return airline, nil