geocoding

package
v1.4.3-rc.1 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 Lodging added in v0.40.0

type Lodging struct {
	Name string
	Lat  float64
	Lon  float64
	// ID is the OpenStreetMap element, such as "osm:node:123456".
	ID string
	// Locality is the town, when Photon has one.
	Locality string
}

Lodging is a hotel or motel from the OpenStreetMap data Photon serves.

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) Lodging added in v0.40.0

func (c *PhotonClient) Lodging(ctx context.Context, lat, lon, radiusKm float64, limit int) ([]Lodging, error)

Lodging lists hotels and motels within radiusKm of a point through Photon's /reverse endpoint with an osm_tag filter (the text search only biases by location, so it returns hotels nationwide). Nameless places are dropped. Best effort for the caller: an error means "none found". limit is capped at 20 and radiusKm at 50.

func (*PhotonClient) Reverse added in v0.41.26

func (c *PhotonClient) Reverse(ctx context.Context, lat, lon float64) (*Result, error)

Reverse names the place at a point through Photon's /reverse endpoint: the nearest feature, mapped like a Search result. A point with nothing near it is (nil, nil); a disabled client or an upstream failure is an error the caller treats as "no label".

func (*PhotonClient) ReverseArea added in v1.2.0

func (c *PhotonClient) ReverseArea(ctx context.Context, lat, lon float64) (string, error)

ReverseArea names the area around a point at city or town level, for a place the caller must not show more exactly: the city or town when the nearest one is a city or a town (a village or hamlet is too small to hide anyone), else the county, else the state. The result is the name plus " area" ("Pasadena area"); nothing finer than that is ever returned (no street, house, POI or postcode). "" with no error means no place was found; a disabled client or an upstream failure is an error.

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"`
	// Locality is the city of a street or house-number result, whose Name starts with the street; omitted for any other result, whose Name
	// is already the place.
	Locality string `json:"locality,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