geo

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 31, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package geo provides common geographic types and calculations. It centralizes location-based data structures and algorithms to ensure consistency across the codebase.

Index

Constants

View Source
const EarthRadius = 6371000.0

EarthRadius is the mean radius of Earth according to WGS-84 in meters

Variables

This section is empty.

Functions

func HaversineDistance

func HaversineDistance(lat1, lon1, lat2, lon2 float64) float64

HaversineDistance calculates the great-circle distance between two points on the Earth's surface given their latitude and longitude in degrees. The result is returned in meters.

Types

type Address

type Address struct {
	Street      string `json:"street,omitempty"`
	HouseNumber string `json:"house_number,omitempty"`
	City        string `json:"city,omitempty"`
	State       string `json:"state,omitempty"`
	Country     string `json:"country,omitempty"`
	PostalCode  string `json:"postal_code,omitempty"`
	Formatted   string `json:"formatted,omitempty"`
}

Address represents a structured address

type BoundingBox

type BoundingBox struct {
	MinLat float64 `json:"minLat"` // Southern edge (minimum latitude)
	MinLon float64 `json:"minLon"` // Western edge (minimum longitude)
	MaxLat float64 `json:"maxLat"` // Northern edge (maximum latitude)
	MaxLon float64 `json:"maxLon"` // Eastern edge (maximum longitude)
}

BoundingBox represents a geographic bounding box with southwest and northeast corners When used in API requests and responses, the field names must be lowercase with camelCase: minLat, minLon, maxLat, maxLon. Using different capitalization (e.g., MinLat) will cause parsing errors in API calls.

func NewBoundingBox

func NewBoundingBox() *BoundingBox

NewBoundingBox creates a new empty bounding box

func (*BoundingBox) Buffer

func (bb *BoundingBox) Buffer(bufferMeters float64)

Buffer adds a buffer around the bounding box in meters This is a rough approximation as it converts meters to degrees using a simple factor that's reasonably accurate near the equator.

func (*BoundingBox) ExtendWithPoint

func (bb *BoundingBox) ExtendWithPoint(lat, lon float64)

ExtendWithPoint extends the bounding box to include the specified point

func (*BoundingBox) String

func (bb *BoundingBox) String() string

String returns a string representation of the bounding box for use in Overpass queries

type Location

type Location struct {
	Latitude  float64 `json:"latitude"`
	Longitude float64 `json:"longitude"`
}

Location represents a geographic coordinate (latitude and longitude) with standardized JSON field names.

Example:

loc := geo.Location{Latitude: 37.7749, Longitude: -122.4194}
dist := geo.HaversineDistance(loc.Latitude, loc.Longitude, 34.0522, -118.2437)

Jump to

Keyboard shortcuts

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