Help us shape the future of Go! Take the 2026 Go Developer Survey

geocoder

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrintCacheSizeAnalysisForFile added in v1.4.0

func PrintCacheSizeAnalysisForFile(file string) error

Types

type Geocoder added in v1.5.0

type Geocoder interface {
	Find(lat, lon float64) (InfoModel, bool)
	// PointsInRadius returns up to limit cached points within radius degrees of
	// (lat, lon), nearest first, and the total number of points that matched
	// (which exceeds len(points) when the result was truncated). The kind
	// filter is a bitmask; a zero mask matches nothing.
	PointsInRadius(lat, lon, radius float64, limit int, kinds PointKind) ([]PointInRadius, int)
	// Metadata returns the cache metadata the geocoder was loaded from; legacy
	// caches that carry none yield the zero value.
	Metadata() cachemodel.Metadata
}

Geocoder is the common interface for both in-memory and disk-backed geocoders.

type InfoModel

type InfoModel struct {
	geomodel.Info
}

type Option added in v1.2.3

type Option interface {
	// contains filtered or unexported methods
}

func WithLogger added in v1.3.0

func WithLogger(logger *slog.Logger) Option

Default: nil

func WithSearchRadius added in v1.2.3

func WithSearchRadius(radius float64) Option

Default: 0.1

type PointInRadius added in v1.6.0

type PointInRadius struct {
	// X is longitude and Y is latitude, in degrees.
	X, Y float64
	// Info is the point's address; Region and Country are filled from the
	// border trees when the stored record left them empty, mirroring what Find
	// reports for a lookup at the point's location.
	Info geomodel.Info
	// Kind is the point's object kind, derived from its weight.
	Kind PointKind
}

PointInRadius is one cache point returned by a radius query.

type PointKind added in v1.6.0

type PointKind uint8

PointKind is the object kind of a cached point, as reported by PointsInRadius. Values are a bitmask, so callers can OR them into a filter.

const (
	PointKindBuilding PointKind = 1 << iota
	PointKindRoad
	PointKindArea

	// PointKindsAll matches every kind.
	PointKindsAll = PointKindBuilding | PointKindRoad | PointKindArea
)

func PointKindFromWeight added in v1.6.0

func PointKindFromWeight(weight uint8) PointKind

PointKindFromWeight derives the object kind from a point's generator weight: 5 is a road (highways are resampled), 3/2 are the industrial/protected area sub-kinds, everything else is a building. It is the Go-side fallback because the in-memory geoInfo does not carry the explicit type byte.

func (PointKind) String added in v1.6.0

func (k PointKind) String() string

String returns the kind as it appears in API responses.

type RGeoCoder

type RGeoCoder struct {
	// contains filtered or unexported fields
}

func LoadGeoCoderFromFile added in v1.2.1

func LoadGeoCoderFromFile(file string, opts ...Option) (*RGeoCoder, error)

func LoadGeoCoderFromReader added in v1.2.1

func LoadGeoCoderFromReader(r io.Reader, opts ...Option) (*RGeoCoder, error)

func NewGeoCoderFromPoints added in v1.5.0

func NewGeoCoderFromPoints(points []cachemodel.Point, opts ...Option) *RGeoCoder

NewGeoCoderFromPoints builds an RGeoCoder from pre-constructed cache model points. This is useful for testing with known data. Regions and countries are initialized empty.

func (*RGeoCoder) CountryAt added in v1.5.0

func (f *RGeoCoder) CountryAt(lat, lon float64) (string, bool)

CountryAt returns the name of the country containing the given coordinates.

func (*RGeoCoder) Find

func (f *RGeoCoder) Find(lat, lon float64) (i InfoModel, ok bool)

func (*RGeoCoder) FindInRadius added in v1.3.0

func (f *RGeoCoder) FindInRadius(lat, lon float64, radius float64) (i InfoModel, ok bool)

func (*RGeoCoder) ForEachPoint added in v1.5.0

func (f *RGeoCoder) ForEachPoint(fn func(cachemodel.Point) bool)

ForEachPoint calls fn for every cached point. Iteration stops early when fn returns false.

func (*RGeoCoder) LoadFromPointsFile deprecated

func (f *RGeoCoder) LoadFromPointsFile(file string) error

Deprecated: Use LoadGeoCoderFromFile instead.

func (*RGeoCoder) Metadata added in v1.5.0

func (f *RGeoCoder) Metadata() cachemodel.Metadata

Metadata returns the cache metadata. The zero value is returned for legacy caches that carry none.

func (*RGeoCoder) NumPoints added in v1.5.0

func (f *RGeoCoder) NumPoints() int

NumPoints returns the number of points in the cache.

func (*RGeoCoder) PointsInRadius added in v1.6.0

func (f *RGeoCoder) PointsInRadius(lat, lon, radius float64, limit int, kinds PointKind) ([]PointInRadius, int)

PointsInRadius returns up to limit cached points within radius degrees of (lat, lon), nearest first, together with the total number of matching points.

func (*RGeoCoder) Zones added in v1.5.0

func (f *RGeoCoder) Zones() []cachemodel.Zone

Zones returns the cache's region and country zones.

type RGeoCoderDisk added in v1.5.0

type RGeoCoderDisk struct {
	// contains filtered or unexported fields
}

RGeoCoderDisk is a disk-backed reverse geocoder that uses mmap for the spatial index and for lazy string resolution. Strings are read from the mmap'd file only when a point is matched.

func LoadGeoCoderFromFileDisk added in v1.5.0

func LoadGeoCoderFromFileDisk(file string, opts ...Option) (*RGeoCoderDisk, error)

LoadGeoCoderFromFileDisk loads a v2 cache file using mmap for the spatial index. This is the default loading path for v2 caches — only string tables and zone polygons are loaded into memory; the KD-tree index is accessed via mmap.

The returned RGeoCoderDisk must be closed after use to release the mmap mapping.

func (*RGeoCoderDisk) Close added in v1.5.0

func (f *RGeoCoderDisk) Close() error

Close releases the mmap resources.

func (*RGeoCoderDisk) CountryAt added in v1.5.0

func (f *RGeoCoderDisk) CountryAt(lat, lon float64) (string, bool)

CountryAt returns the name of the country containing the given coordinates.

func (*RGeoCoderDisk) Find added in v1.5.0

func (f *RGeoCoderDisk) Find(lat, lon float64) (InfoModel, bool)

Find returns the closest address for the given coordinates.

func (*RGeoCoderDisk) FindInRadius added in v1.5.0

func (f *RGeoCoderDisk) FindInRadius(lat, lon float64, radius float64) (i InfoModel, ok bool)

FindInRadius returns the closest address within the given radius.

func (*RGeoCoderDisk) ForEachPoint added in v1.5.0

func (f *RGeoCoderDisk) ForEachPoint(fn func(cachemodel.Point) bool)

ForEachPoint calls fn for every cached point. Iteration stops early when fn returns false. String IDs are resolved while iterating.

func (*RGeoCoderDisk) Metadata added in v1.5.0

func (f *RGeoCoderDisk) Metadata() cachemodel.Metadata

Metadata returns the cache metadata.

func (*RGeoCoderDisk) NumPoints added in v1.5.0

func (f *RGeoCoderDisk) NumPoints() int

NumPoints returns the number of points in the cache.

func (*RGeoCoderDisk) PointsInRadius added in v1.6.0

func (f *RGeoCoderDisk) PointsInRadius(lat, lon, radius float64, limit int, kinds PointKind) ([]PointInRadius, int)

PointsInRadius returns up to limit cached points within radius degrees of (lat, lon), nearest first, together with the total number of matching points.

func (*RGeoCoderDisk) Zones added in v1.5.0

func (f *RGeoCoderDisk) Zones() []cachemodel.Zone

Zones returns the cache's region and country zones.

Jump to

Keyboard shortcuts

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