geocoding

package
v0.18.64 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package geocoding wraps Open-Meteo's free geocoding endpoint (https://geocoding-api.open-meteo.com/v1/search) for forward- geocoding text input → lat/lon. Same provider we use for weather, so the privacy trade-off is consistent: city/place names leave the box during search, but no per-user identifiers are sent.

The endpoint resolves city- and town-level inputs (Dallas, Big Bend National Park). It does NOT do street addresses; for those, a future slice would need a self-hosted Nominatim (heavyweight) or a keyed commercial geocoder. The trip-planner use case in slice 2 is "where am I going at the city level," which this covers.

Index

Constants

View Source
const DefaultBaseURL = "https://geocoding-api.open-meteo.com"

DefaultBaseURL is Open-Meteo's geocoding endpoint. Override on the Client for tests.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	HTTP    *http.Client
	BaseURL string
}

Client is a thin wrapper around the geocoding endpoint.

func NewClient

func NewClient() *Client

NewClient returns a Client with sane defaults.

func (*Client) Search

func (c *Client) Search(ctx context.Context, name string, count int) ([]Result, error)

Search forward-geocodes name, returning at most count matches (capped to 10 so a typo can't pull a long page). Returns an empty slice (not an error) when Open-Meteo finds nothing.

type PhotonClient

type PhotonClient struct {
	HTTP    *http.Client
	BaseURL string
}

PhotonClient wraps a self-hosted Photon HTTP API. Photon's GeoJSON FeatureCollection is mapped onto the same Result shape Open-Meteo uses so the SPA contract stays unchanged. Empty BaseURL disables the client; the multiplexer falls through to Open-Meteo.

func NewPhotonClient

func NewPhotonClient(baseURL string) *PhotonClient

NewPhotonClient returns a Photon client. BaseURL is the in-cluster Service URL (e.g. http://photon.photon.svc.cluster.local), no trailing slash. Empty disables.

func (*PhotonClient) Enabled

func (c *PhotonClient) Enabled() bool

Enabled reports whether a base URL is configured.

func (*PhotonClient) Search

func (c *PhotonClient) Search(ctx context.Context, name string, count int) ([]Result, error)

Search forward-geocodes name through Photon's /api endpoint. Maps Photon properties onto the Result shape: name combines housenumber + street when present, falls through to .name; admin1 = state; country_code = countrycode (Photon emits lowercased, we uppercase to match Open-Meteo). Population isn't published by Photon — left at zero so the SPA's "highest-population first" sort still works for Open-Meteo fallbacks.

type Result

type Result struct {
	Name        string  `json:"name"`
	Latitude    float64 `json:"latitude"`
	Longitude   float64 `json:"longitude"`
	Country     string  `json:"country,omitempty"`
	CountryCode string  `json:"country_code,omitempty"`
	// Admin1 is state / province / region. Useful for disambiguating
	// "Dallas, TX" from "Dallas, OR".
	Admin1 string `json:"admin1,omitempty"`
	// Population helps the SPA show the relevance order Open-Meteo
	// already applies (top result is highest-population match).
	Population int    `json:"population,omitempty"`
	Timezone   string `json:"timezone,omitempty"`
}

Result is one search match. Fields mirror Open-Meteo's response, renamed to Go conventions; the SPA gets these names verbatim via the API handler.

Jump to

Keyboard shortcuts

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