geoapify

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 12 Imported by: 0

README

CI codecov Go Reference

GeoApify Go

The complete Go SDK for the GeoApify Location Platform

geoapify-go is a fully-typed, idiomatic Go client for all GeoApify REST APIs. It uses a fluent builder pattern for ergonomic request construction and supports optional retry with exponential backoff.

🎯 Goals and principles

  • Complete API coverage — every GeoApify REST endpoint in one package
  • Fluent API — discoverable builder pattern with method chaining terminated by .Do(ctx)
  • Zero external dependencies — built entirely on the Go standard library
  • Production-ready — configurable retry with exponential backoff, context-aware cancellation, typed errors
  • Well-tested — comprehensive unit tests with httptest mocks and optional end-to-end tests

✨ Features

📍 Geocoding — forward, reverse, and autocomplete address search

📦 Batch Geocoding — geocode up to 1000 addresses at once with async job polling

🌐 IP Geolocation — detect user location by IP address

📮 Postcode — search postcodes by coordinates or area

🚗 Routing — calculate routes for cars, trucks, bicycles, pedestrians, and more

📊 Route Matrix — time-distance matrices for multiple origins and destinations

🗺️ Map Matching — snap GPS tracks to road networks

📋 Route Planner — solve vehicle routing problems (TSP, CVRP, VRPTW, and more)

⏱️ Isolines — calculate isochrones and isodistances for reachability analysis

📌 Places — find points of interest by category and location

🏢 Place Details — get detailed information and geometry for any place

🗾 Boundaries — query administrative boundaries and subdivisions

🚀 Installation

go get github.com/dkhalife/geoapify-go

📖 Usage

Creating a client
import geoapify "github.com/dkhalife/geoapify-go"

// Basic client
client := geoapify.NewClient("YOUR_API_KEY")

// With retry logic
client := geoapify.NewClient("YOUR_API_KEY",
    geoapify.WithRetry(3, 500*time.Millisecond, 10*time.Second),
)

// With custom HTTP client
client := geoapify.NewClient("YOUR_API_KEY",
    geoapify.WithHTTPClient(&http.Client{Timeout: 30 * time.Second}),
)
Forward Geocoding
results, err := client.Geocoding().
    Search("1313 Broadway, Tacoma, WA").
    WithLimit(5).
    WithLang("en").
    WithFilter(geoapify.CountryFilter("us")).
    WithFormat(geoapify.FormatJSON).
    Do(ctx)
Reverse Geocoding
results, err := client.Geocoding().
    Reverse(52.479, 13.213).
    WithLang("en").
    Do(ctx)
Address Autocomplete
results, err := client.Geocoding().
    Autocomplete("Lessingstraße 3").
    WithType(geoapify.TypeCity).
    Do(ctx)
Routing
route, err := client.Routing().
    Waypoints(
        geoapify.LatLon(50.679, 4.569),
        geoapify.LatLon(50.661, 4.578),
    ).
    WithMode(geoapify.ModeDrive).
    WithDetails(geoapify.DetailInstructions, geoapify.DetailElevation).
    Do(ctx)
Places
places, err := client.Places().
    Categories("commercial.supermarket").
    WithFilter(geoapify.CircleFilter(-87.77, 41.87, 5000)).
    WithLimit(20).
    Do(ctx)
Isolines
iso, err := client.Isolines().
    At(28.293, -81.550).
    WithType(geoapify.IsolineTime).
    WithMode(geoapify.ModeDrive).
    WithRange(1800).
    Do(ctx)

⚙️ Configuration

Option Description Default
WithHTTPClient(client) Custom *http.Client for all requests http.DefaultClient
WithBaseURL(url) Override the API base URL https://api.geoapify.com
WithRetry(max, initial, maxDelay) Enable retry with exponential backoff and jitter Disabled
Retry behavior

When enabled, the client retries on:

  • 429 Too Many Requests — respects Retry-After header
  • 5xx Server Errors — transient server failures

Retries are context-aware and will stop if the context is cancelled or expired.

🛠️ Development

Requirements
  • Go 1.23+
Commands
make build    # Build the package
make lint     # Run golangci-lint
make test     # Run tests with race detector
make cover    # Generate coverage report
Running E2E tests
export GEOAPIFY_API_KEY="your-api-key"
make test

🤝 Contributing

Contributions are welcome! If you would like to contribute to this repo, feel free to fork the repo and submit pull requests. If you have ideas but aren't familiar with code, you can also open issues.

🔒 License

See the LICENSE file for more details.

Documentation

Overview

Package geoapify provides a Go client for the GeoApify Location Platform APIs.

Create a client with your API key and use the fluent builder pattern to construct and execute API requests:

client := geoapify.NewClient("YOUR_API_KEY")
results, err := client.Geocoding().
    Search("1313 Broadway, Tacoma, WA").
    WithLimit(5).
    Do(ctx)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CircleBias

func CircleBias(lon, lat, radiusMeters float64) string

CircleBias creates a circle bias.

func CircleFilter

func CircleFilter(lon, lat, radiusMeters float64) string

CircleFilter creates a circle filter.

func CountryBias

func CountryBias(codes ...string) string

CountryBias creates a country code bias.

func CountryFilter

func CountryFilter(codes ...string) string

CountryFilter creates a country code filter.

func PlaceFilter

func PlaceFilter(placeID string) string

PlaceFilter creates a place ID filter.

func ProximityBias

func ProximityBias(lon, lat float64) string

ProximityBias creates a proximity bias.

func RectBias

func RectBias(lon1, lat1, lon2, lat2 float64) string

RectBias creates a rectangle bias.

func RectFilter

func RectFilter(lon1, lat1, lon2, lat2 float64) string

RectFilter creates a rectangle filter.

Types

type APIError

type APIError struct {
	StatusCode int    `json:"statusCode"`
	Message    string `json:"message"`
	RawBody    []byte `json:"-"`
}

APIError represents an error returned by the GeoApify API.

func IsAPIError

func IsAPIError(err error) (*APIError, bool)

IsAPIError checks if the error is an APIError and returns it.

func (*APIError) Error

func (e *APIError) Error() string

type Address

type Address struct {
	Name         string      `json:"name,omitempty"`
	Country      string      `json:"country,omitempty"`
	CountryCode  string      `json:"country_code,omitempty"`
	State        string      `json:"state,omitempty"`
	StateCode    string      `json:"state_code,omitempty"`
	County       string      `json:"county,omitempty"`
	CountyCode   string      `json:"county_code,omitempty"`
	Postcode     string      `json:"postcode,omitempty"`
	City         string      `json:"city,omitempty"`
	Street       string      `json:"street,omitempty"`
	HouseNumber  string      `json:"housenumber,omitempty"`
	Suburb       string      `json:"suburb,omitempty"`
	District     string      `json:"district,omitempty"`
	Lon          float64     `json:"lon"`
	Lat          float64     `json:"lat"`
	Formatted    string      `json:"formatted,omitempty"`
	AddressLine1 string      `json:"address_line1,omitempty"`
	AddressLine2 string      `json:"address_line2,omitempty"`
	ResultType   string      `json:"result_type,omitempty"`
	Distance     float64     `json:"distance,omitempty"`
	PlaceID      string      `json:"place_id,omitempty"`
	Category     string      `json:"category,omitempty"`
	Rank         *Rank       `json:"rank,omitempty"`
	Timezone     *Timezone   `json:"timezone,omitempty"`
	Datasource   *Datasource `json:"datasource,omitempty"`
}

Address represents a geocoded address result.

type AutocompleteRequest

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

AutocompleteRequest is a builder for address autocomplete requests.

func (*AutocompleteRequest) Do

Do executes the autocomplete request.

func (*AutocompleteRequest) WithBias

func (r *AutocompleteRequest) WithBias(biases ...string) *AutocompleteRequest

WithBias adds geocoding biases (joined with |).

func (*AutocompleteRequest) WithFilter

func (r *AutocompleteRequest) WithFilter(filters ...string) *AutocompleteRequest

WithFilter adds geocoding filters (joined with |).

func (*AutocompleteRequest) WithFormat

WithFormat sets the response format.

func (*AutocompleteRequest) WithLang

WithLang sets the response language.

func (*AutocompleteRequest) WithType

WithType sets the location type filter.

type BatchForwardRequest

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

BatchForwardRequest is a builder for submitting a forward batch geocoding job.

func (*BatchForwardRequest) Do

Do executes the forward batch geocoding request.

func (*BatchForwardRequest) WithBias

func (r *BatchForwardRequest) WithBias(biases ...string) *BatchForwardRequest

WithBias adds geocoding biases (joined with |).

func (*BatchForwardRequest) WithFilter

func (r *BatchForwardRequest) WithFilter(filters ...string) *BatchForwardRequest

WithFilter adds geocoding filters (joined with |).

func (*BatchForwardRequest) WithLang

WithLang sets the response language.

func (*BatchForwardRequest) WithType

WithType sets the location type filter.

type BatchGeocodingService

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

BatchGeocodingService provides access to the Batch Geocoding API.

func (*BatchGeocodingService) GetForwardResult

func (s *BatchGeocodingService) GetForwardResult(jobID string) *BatchResultRequest

GetForwardResult creates a builder to poll forward batch geocoding results.

func (*BatchGeocodingService) GetReverseResult

func (s *BatchGeocodingService) GetReverseResult(jobID string) *BatchResultRequest

GetReverseResult creates a builder to poll reverse batch geocoding results.

func (*BatchGeocodingService) SubmitForward

func (s *BatchGeocodingService) SubmitForward(addresses []string) *BatchForwardRequest

SubmitForward creates a builder for submitting a forward batch geocoding job.

func (*BatchGeocodingService) SubmitReverse

func (s *BatchGeocodingService) SubmitReverse(coordinates [][2]float64) *BatchReverseRequest

SubmitReverse creates a builder for submitting a reverse batch geocoding job.

type BatchJobResponse

type BatchJobResponse struct {
	ID     string `json:"id"`
	Status string `json:"status"`
	URL    string `json:"url,omitempty"`
}

BatchJobResponse represents the response when submitting a batch job.

type BatchResultRequest

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

BatchResultRequest is a builder for polling batch geocoding results.

func (*BatchResultRequest) Do

Do executes the batch result polling request.

func (*BatchResultRequest) WithFormat

func (r *BatchResultRequest) WithFormat(v string) *BatchResultRequest

WithFormat sets the response format.

type BatchResultResponse

type BatchResultResponse struct {
	// When pending
	ID     string `json:"id,omitempty"`
	Status string `json:"status,omitempty"`
	// When complete - results is an array of Address objects
	Results []Address `json:"-"`
	// Raw holds the raw JSON for flexible parsing
	Raw json.RawMessage `json:"-"`
}

BatchResultResponse represents the response when polling for batch results.

func (*BatchResultResponse) UnmarshalJSON

func (r *BatchResultResponse) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom unmarshalling for BatchResultResponse. If the JSON is an array, it represents completed results. If it is an object with "status", it represents a pending job.

type BatchReverseRequest

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

BatchReverseRequest is a builder for submitting a reverse batch geocoding job.

func (*BatchReverseRequest) Do

Do executes the reverse batch geocoding request.

func (*BatchReverseRequest) WithLang

WithLang sets the response language.

func (*BatchReverseRequest) WithType

WithType sets the location type filter.

type BoundariesConsistsOfRequest

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

BoundariesConsistsOfRequest is a builder for boundaries consists-of API requests.

func (*BoundariesConsistsOfRequest) Do

Do executes the boundaries consists-of request.

func (*BoundariesConsistsOfRequest) WithBoundary

WithBoundary sets the boundary type filter.

func (*BoundariesConsistsOfRequest) WithGeometry

WithGeometry sets the geometry type.

func (*BoundariesConsistsOfRequest) WithLang

WithLang sets the response language.

func (*BoundariesConsistsOfRequest) WithSublevel

WithSublevel sets the sublevel depth.

type BoundariesPartOfRequest

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

BoundariesPartOfRequest is a builder for boundaries part-of API requests.

func (*BoundariesPartOfRequest) Do

Do executes the boundaries part-of request.

func (*BoundariesPartOfRequest) WithBoundary

WithBoundary sets the boundary type filter.

func (*BoundariesPartOfRequest) WithGeometry

WithGeometry sets the geometry type.

func (*BoundariesPartOfRequest) WithLang

WithLang sets the response language.

type BoundariesService

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

BoundariesService provides access to the GeoApify Boundaries API.

func (*BoundariesService) ConsistsOf

ConsistsOf creates a new boundaries consists-of request builder by place ID.

func (*BoundariesService) PartOf

func (s *BoundariesService) PartOf(lat, lon float64) *BoundariesPartOfRequest

PartOf creates a new boundaries part-of request builder by coordinates.

func (*BoundariesService) PartOfByID

PartOfByID creates a new boundaries part-of request builder by place ID.

type BoundaryType

type BoundaryType string

BoundaryType represents the boundary type.

const (
	BoundaryAdministrative  BoundaryType = "administrative"
	BoundaryPostalCode      BoundaryType = "postal_code"
	BoundaryPolitical       BoundaryType = "political"
	BoundaryLowEmissionZone BoundaryType = "low_emission_zone"
)

type Client

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

Client is the GeoApify API client.

func NewClient

func NewClient(apiKey string, opts ...Option) *Client

NewClient creates a new GeoApify client with the given API key and options.

func (*Client) BatchGeocoding

func (c *Client) BatchGeocoding() *BatchGeocodingService

BatchGeocoding returns a batch geocoding service.

func (*Client) Boundaries

func (c *Client) Boundaries() *BoundariesService

Boundaries returns a boundaries service.

func (*Client) Geocoding

func (c *Client) Geocoding() *GeocodingService

Geocoding returns a geocoding service for building geocoding requests.

func (*Client) IPGeolocation

func (c *Client) IPGeolocation() *IPGeolocationService

IPGeolocation returns an IP geolocation service.

func (*Client) Isolines

func (c *Client) Isolines() *IsolinesService

Isolines returns an isolines service for building isoline requests.

func (*Client) MapMatching

func (c *Client) MapMatching() *MapMatchingService

MapMatching returns a map matching service.

func (*Client) PlaceDetails

func (c *Client) PlaceDetails() *PlaceDetailsService

PlaceDetails returns a place details service.

func (*Client) Places

func (c *Client) Places() *PlacesService

Places returns a places service for building places requests.

func (*Client) Postcode

func (c *Client) Postcode() *PostcodeService

Postcode returns a postcode service.

func (*Client) RouteMatrix

func (c *Client) RouteMatrix() *RouteMatrixService

RouteMatrix returns a route matrix service.

func (*Client) RoutePlanner

func (c *Client) RoutePlanner() *RoutePlannerService

RoutePlanner returns a route planner service.

func (*Client) Routing

func (c *Client) Routing() *RoutingService

Routing returns a routing service for building routing requests.

type Datasource

type Datasource struct {
	SourceName  string `json:"sourcename,omitempty"`
	Attribution string `json:"attribution,omitempty"`
	License     string `json:"license,omitempty"`
	URL         string `json:"url,omitempty"`
}

Datasource contains data source attribution.

type Format

type Format string

Format represents the response format.

const (
	FormatJSON    Format = "json"
	FormatGeoJSON Format = "geojson"
	FormatXML     Format = "xml"
)

type GeoJSONFeature

type GeoJSONFeature struct {
	Type       string           `json:"type"`
	Geometry   *GeoJSONGeometry `json:"geometry,omitempty"`
	Properties map[string]any   `json:"properties,omitempty"`
}

GeoJSONFeature is a generic GeoJSON Feature.

type GeoJSONFeatureCollection

type GeoJSONFeatureCollection struct {
	Type       string           `json:"type"`
	Features   []GeoJSONFeature `json:"features"`
	Properties map[string]any   `json:"properties,omitempty"`
}

GeoJSONFeatureCollection is a generic GeoJSON FeatureCollection.

type GeoJSONGeometry

type GeoJSONGeometry struct {
	Type        string `json:"type"`
	Coordinates any    `json:"coordinates"`
}

GeoJSONGeometry is a generic GeoJSON Geometry.

type GeocodingParsed

type GeocodingParsed struct {
	HouseNumber  string `json:"housenumber,omitempty"`
	Street       string `json:"street,omitempty"`
	Postcode     string `json:"postcode,omitempty"`
	City         string `json:"city,omitempty"`
	State        string `json:"state,omitempty"`
	Country      string `json:"country,omitempty"`
	ExpectedType string `json:"expected_type,omitempty"`
}

GeocodingParsed contains the parsed components of a geocoding query.

type GeocodingQuery

type GeocodingQuery struct {
	Text   string           `json:"text,omitempty"`
	Parsed *GeocodingParsed `json:"parsed,omitempty"`
}

GeocodingQuery contains query metadata returned by the API.

type GeocodingResponse

type GeocodingResponse struct {
	Results []Address       `json:"results"`
	Query   *GeocodingQuery `json:"query,omitempty"`
}

GeocodingResponse represents the response from geocoding APIs.

type GeocodingService

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

GeocodingService provides access to the GeoApify Geocoding APIs.

func (*GeocodingService) Autocomplete

func (s *GeocodingService) Autocomplete(text string) *AutocompleteRequest

Autocomplete creates a new address autocomplete request builder.

func (*GeocodingService) Reverse

func (s *GeocodingService) Reverse(lat, lon float64) *ReverseGeocodingRequest

Reverse creates a new reverse geocoding request builder.

func (*GeocodingService) Search

func (s *GeocodingService) Search(text string) *SearchRequest

Search creates a new forward geocoding request builder.

type GeometryType

type GeometryType string

GeometryType represents the boundary geometry type.

const (
	GeometryPoint GeometryType = "point"
	Geometry1000  GeometryType = "geometry_1000"
	Geometry5000  GeometryType = "geometry_5000"
	Geometry10000 GeometryType = "geometry_10000"
)

type IPGeolocationRequest

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

IPGeolocationRequest is a builder for IP geolocation API requests.

func (*IPGeolocationRequest) Do

Do executes the IP geolocation request.

func (*IPGeolocationRequest) WithIP

WithIP sets a specific IP address to look up.

type IPGeolocationResponse

type IPGeolocationResponse struct {
	IP        string               `json:"ip,omitempty"`
	City      *IPLocationCity      `json:"city,omitempty"`
	State     *IPLocationState     `json:"state,omitempty"`
	Country   *IPLocationCountry   `json:"country,omitempty"`
	Continent *IPLocationContinent `json:"continent,omitempty"`
	Location  *IPLocationCoords    `json:"location,omitempty"`
}

IPGeolocationResponse is the response from the IP geolocation API.

type IPGeolocationService

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

IPGeolocationService provides access to the GeoApify IP Geolocation API.

func (*IPGeolocationService) Lookup

Lookup creates a new IP geolocation request builder that auto-detects the IP.

type IPLocationCity

type IPLocationCity struct {
	Name string `json:"name,omitempty"`
}

IPLocationCity contains city information.

type IPLocationContinent

type IPLocationContinent struct {
	Name string `json:"name,omitempty"`
	Code string `json:"code,omitempty"`
}

IPLocationContinent contains continent information.

type IPLocationCoords

type IPLocationCoords struct {
	Latitude  float64 `json:"latitude,omitempty"`
	Longitude float64 `json:"longitude,omitempty"`
}

IPLocationCoords contains geographic coordinates.

type IPLocationCountry

type IPLocationCountry struct {
	Name       string           `json:"name,omitempty"`
	NameNative string           `json:"name_native,omitempty"`
	ISOCode    string           `json:"iso_code,omitempty"`
	PhoneCode  string           `json:"phone_code,omitempty"`
	Capital    string           `json:"capital,omitempty"`
	Flag       string           `json:"flag,omitempty"`
	Languages  []IPLocationLang `json:"languages,omitempty"`
	Currency   string           `json:"currency,omitempty"`
}

IPLocationCountry contains country information.

type IPLocationLang

type IPLocationLang struct {
	ISOCode    string `json:"iso_code,omitempty"`
	Name       string `json:"name,omitempty"`
	NameNative string `json:"name_native,omitempty"`
}

IPLocationLang contains language information.

type IPLocationState

type IPLocationState struct {
	Name string `json:"name,omitempty"`
}

IPLocationState contains state/subdivision information.

type IsolineRequest

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

IsolineRequest is a builder for an isoline API call.

func (*IsolineRequest) Do

Do executes the isoline request.

func (*IsolineRequest) WithAvoid

func (r *IsolineRequest) WithAvoid(avoids ...string) *IsolineRequest

WithAvoid sets features to avoid.

func (*IsolineRequest) WithMaxSpeed

func (r *IsolineRequest) WithMaxSpeed(n int) *IsolineRequest

WithMaxSpeed sets the maximum speed.

func (*IsolineRequest) WithMode

func (r *IsolineRequest) WithMode(m TravelMode) *IsolineRequest

WithMode sets the travel mode.

func (*IsolineRequest) WithRange

func (r *IsolineRequest) WithRange(ranges ...int) *IsolineRequest

WithRange sets the isoline range values.

func (*IsolineRequest) WithRouteType

func (r *IsolineRequest) WithRouteType(rt RouteType) *IsolineRequest

WithRouteType sets the route type.

func (*IsolineRequest) WithTraffic

func (r *IsolineRequest) WithTraffic(t TrafficModel) *IsolineRequest

WithTraffic sets the traffic model.

func (*IsolineRequest) WithType

func (r *IsolineRequest) WithType(t IsolineType) *IsolineRequest

WithType sets the isoline type (time or distance).

func (*IsolineRequest) WithUnits

func (r *IsolineRequest) WithUnits(u Units) *IsolineRequest

WithUnits sets the distance units.

type IsolineType

type IsolineType string

IsolineType represents the isoline calculation type.

const (
	IsolineTime     IsolineType = "time"
	IsolineDistance IsolineType = "distance"
)

type IsolinesService

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

IsolinesService provides access to the GeoApify Isolines API.

func (*IsolinesService) At

func (s *IsolinesService) At(lat, lon float64) *IsolineRequest

At creates a new IsolineRequest for the given coordinates.

func (*IsolinesService) ByID

func (s *IsolinesService) ByID(id string) *IsolineRequest

ByID creates a new IsolineRequest to retrieve a previously generated isoline.

type LegStep

type LegStep struct {
	Distance    float64          `json:"distance"`
	Time        float64          `json:"time"`
	FromIndex   int              `json:"from_index"`
	ToIndex     int              `json:"to_index"`
	Toll        bool             `json:"toll,omitempty"`
	Ferry       bool             `json:"ferry,omitempty"`
	Tunnel      bool             `json:"tunnel,omitempty"`
	Bridge      bool             `json:"bridge,omitempty"`
	Roundabout  bool             `json:"roundabout,omitempty"`
	Speed       float64          `json:"speed,omitempty"`
	SpeedLimit  float64          `json:"speed_limit,omitempty"`
	TruckLimit  float64          `json:"truck_limit,omitempty"`
	Surface     string           `json:"surface,omitempty"`
	LaneCount   int              `json:"lane_count,omitempty"`
	RoadClass   string           `json:"road_class,omitempty"`
	Name        string           `json:"name,omitempty"`
	Instruction *StepInstruction `json:"instruction,omitempty"`
}

LegStep represents a step within a route leg.

type Location

type Location struct {
	Lat float64
	Lon float64
}

Location represents a geographic coordinate pair.

func LatLon

func LatLon(lat, lon float64) Location

LatLon creates a Location from latitude and longitude.

func LonLat

func LonLat(lon, lat float64) Location

LonLat creates a Location from longitude and latitude.

type LocationType

type LocationType string

LocationType represents a location type filter.

const (
	TypeCountry  LocationType = "country"
	TypeState    LocationType = "state"
	TypeCity     LocationType = "city"
	TypePostcode LocationType = "postcode"
	TypeStreet   LocationType = "street"
	TypeAmenity  LocationType = "amenity"
	TypeLocality LocationType = "locality"
)

type MapMatchingRequest

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

MapMatchingRequest is a builder for map matching API requests.

func (*MapMatchingRequest) Do

Do executes the map matching request.

func (*MapMatchingRequest) Waypoints

func (r *MapMatchingRequest) Waypoints(waypoints ...MapMatchingWaypoint) *MapMatchingRequest

Waypoints sets the waypoints to match.

func (*MapMatchingRequest) WithMode

WithMode sets the travel mode.

type MapMatchingService

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

MapMatchingService provides access to the GeoApify Map Matching API.

func (*MapMatchingService) Match

Match creates a new map matching request builder.

type MapMatchingWaypoint

type MapMatchingWaypoint struct {
	Location  [2]float64 `json:"location"`
	Timestamp string     `json:"timestamp,omitempty"`
	Bearing   *float64   `json:"bearing,omitempty"`
}

MapMatchingWaypoint represents a waypoint for map matching.

type Option

type Option func(*Client)

Option configures the Client.

func WithBaseURL

func WithBaseURL(url string) Option

WithBaseURL overrides the default API base URL.

func WithHTTPClient

func WithHTTPClient(c *http.Client) Option

WithHTTPClient sets a custom HTTP client.

func WithRetry

func WithRetry(maxRetries int, initialDelay, maxDelay time.Duration) Option

WithRetry enables retry with exponential backoff and jitter. Retries are attempted on 429 (rate limit) and 5xx (server error) responses. maxRetries is the maximum number of retry attempts (0 means no retries). initialDelay is the delay before the first retry. maxDelay is the maximum delay between retries.

type PlaceDetailsRequest

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

PlaceDetailsRequest is a builder for place details requests.

func (*PlaceDetailsRequest) Do

Do executes the place details request.

func (*PlaceDetailsRequest) WithFeatures

func (r *PlaceDetailsRequest) WithFeatures(features ...string) *PlaceDetailsRequest

WithFeatures sets the features to include in the response.

func (*PlaceDetailsRequest) WithLang

WithLang sets the response language.

type PlaceDetailsService

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

PlaceDetailsService provides access to the Place Details API.

func (*PlaceDetailsService) ByCoordinates

func (s *PlaceDetailsService) ByCoordinates(lat, lon float64) *PlaceDetailsRequest

ByCoordinates creates a place details request by coordinates.

func (*PlaceDetailsService) ByID

ByID creates a place details request by place ID.

type PlacesRequest

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

PlacesRequest is a builder for a places API call.

func (*PlacesRequest) Do

Do executes the places request.

func (*PlacesRequest) WithBias

func (r *PlacesRequest) WithBias(biases ...string) *PlacesRequest

WithBias adds biases to the request.

func (*PlacesRequest) WithConditions

func (r *PlacesRequest) WithConditions(conditions ...string) *PlacesRequest

WithConditions adds conditions to the request.

func (*PlacesRequest) WithFilter

func (r *PlacesRequest) WithFilter(filters ...string) *PlacesRequest

WithFilter adds filters to the request.

func (*PlacesRequest) WithLang

func (r *PlacesRequest) WithLang(v string) *PlacesRequest

WithLang sets the response language.

func (*PlacesRequest) WithLimit

func (r *PlacesRequest) WithLimit(n int) *PlacesRequest

WithLimit sets the maximum number of results.

func (*PlacesRequest) WithName

func (r *PlacesRequest) WithName(v string) *PlacesRequest

WithName sets a name filter for the request.

func (*PlacesRequest) WithOffset

func (r *PlacesRequest) WithOffset(n int) *PlacesRequest

WithOffset sets the result offset for pagination.

type PlacesService

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

PlacesService provides access to the GeoApify Places API.

func (*PlacesService) Categories

func (s *PlacesService) Categories(categories ...string) *PlacesRequest

Categories creates a new PlacesRequest for the given categories.

type PlannerAgent

type PlannerAgent struct {
	ID               string         `json:"id,omitempty"`
	Description      string         `json:"description,omitempty"`
	StartLocation    [2]float64     `json:"start_location,omitempty"`
	StartLocationIdx *int           `json:"start_location_index,omitempty"`
	EndLocation      [2]float64     `json:"end_location,omitempty"`
	EndLocationIdx   *int           `json:"end_location_index,omitempty"`
	PickupCapacity   *int           `json:"pickup_capacity,omitempty"`
	DeliveryCapacity *int           `json:"delivery_capacity,omitempty"`
	Capabilities     []string       `json:"capabilities,omitempty"`
	TimeWindows      [][2]int       `json:"time_windows,omitempty"`
	Breaks           []PlannerBreak `json:"breaks,omitempty"`
}

PlannerAgent represents a vehicle or driver in the route planner.

type PlannerAgentResult

type PlannerAgentResult struct {
	AgentIndex int                `json:"agent_index"`
	Route      []PlannerRouteStep `json:"route,omitempty"`
	Distance   float64            `json:"distance"`
	Time       float64            `json:"time"`
}

PlannerAgentResult represents the result for a single agent.

type PlannerBreak

type PlannerBreak struct {
	Duration    int      `json:"duration"`
	TimeWindows [][2]int `json:"time_windows,omitempty"`
}

PlannerBreak represents a break for an agent.

type PlannerJob

type PlannerJob struct {
	ID             string     `json:"id,omitempty"`
	Description    string     `json:"description,omitempty"`
	Location       [2]float64 `json:"location,omitempty"`
	LocationIdx    *int       `json:"location_index,omitempty"`
	Priority       *int       `json:"priority,omitempty"`
	Duration       *int       `json:"duration,omitempty"`
	PickupAmount   *int       `json:"pickup_amount,omitempty"`
	DeliveryAmount *int       `json:"delivery_amount,omitempty"`
	Requirements   []string   `json:"requirements,omitempty"`
	TimeWindows    [][2]int   `json:"time_windows,omitempty"`
}

PlannerJob represents a job to be assigned to an agent.

type PlannerLocation

type PlannerLocation struct {
	ID       string     `json:"id,omitempty"`
	Location [2]float64 `json:"location"`
}

PlannerLocation represents a reusable location.

type PlannerRouteStep

type PlannerRouteStep struct {
	Type     string  `json:"type,omitempty"`
	JobIndex *int    `json:"job_index,omitempty"`
	Distance float64 `json:"distance,omitempty"`
	Time     float64 `json:"time,omitempty"`
}

PlannerRouteStep represents a step in an agent's route.

type PlannerShipment

type PlannerShipment struct {
	ID           string              `json:"id"`
	Pickup       PlannerShipmentStop `json:"pickup"`
	Delivery     PlannerShipmentStop `json:"delivery"`
	Requirements []string            `json:"requirements,omitempty"`
	Priority     *int                `json:"priority,omitempty"`
	Description  string              `json:"description,omitempty"`
	Amount       *int                `json:"amount,omitempty"`
}

PlannerShipment represents a shipment with pickup and delivery stops.

type PlannerShipmentStop

type PlannerShipmentStop struct {
	Location    [2]float64 `json:"location,omitempty"`
	LocationIdx *int       `json:"location_index,omitempty"`
	Duration    *int       `json:"duration,omitempty"`
	TimeWindows [][2]int   `json:"time_windows,omitempty"`
}

PlannerShipmentStop represents a pickup or delivery stop.

type PostcodeRequest

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

PostcodeRequest is a builder for postcode API requests.

func (*PostcodeRequest) Do

Do executes the postcode request.

func (*PostcodeRequest) WithBias

func (r *PostcodeRequest) WithBias(biases ...string) *PostcodeRequest

WithBias sets the result biases.

func (*PostcodeRequest) WithFilter

func (r *PostcodeRequest) WithFilter(filters ...string) *PostcodeRequest

WithFilter sets the result filters.

func (*PostcodeRequest) WithFormat

func (r *PostcodeRequest) WithFormat(f Format) *PostcodeRequest

WithFormat sets the response format.

func (*PostcodeRequest) WithGeometry

func (r *PostcodeRequest) WithGeometry(g GeometryType) *PostcodeRequest

WithGeometry sets the geometry type.

func (*PostcodeRequest) WithLang

func (r *PostcodeRequest) WithLang(v string) *PostcodeRequest

WithLang sets the response language.

func (*PostcodeRequest) WithLimit

func (r *PostcodeRequest) WithLimit(n int) *PostcodeRequest

WithLimit sets the maximum number of results.

type PostcodeService

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

PostcodeService provides access to the GeoApify Postcode API.

func (*PostcodeService) Search

func (s *PostcodeService) Search(lat, lon float64) *PostcodeRequest

Search creates a new postcode request builder with the given coordinates.

type Rank

type Rank struct {
	Importance              float64 `json:"importance,omitempty"`
	Popularity              float64 `json:"popularity,omitempty"`
	Confidence              float64 `json:"confidence,omitempty"`
	ConfidenceCityLevel     float64 `json:"confidence_city_level,omitempty"`
	ConfidenceStreetLevel   float64 `json:"confidence_street_level,omitempty"`
	ConfidenceBuildingLevel float64 `json:"confidence_building_level,omitempty"`
	MatchType               string  `json:"match_type,omitempty"`
}

Rank contains confidence and match information.

type ReverseGeocodingRequest

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

ReverseGeocodingRequest is a builder for reverse geocoding requests.

func (*ReverseGeocodingRequest) Do

Do executes the reverse geocoding request.

func (*ReverseGeocodingRequest) WithFormat

WithFormat sets the response format.

func (*ReverseGeocodingRequest) WithLang

WithLang sets the response language.

func (*ReverseGeocodingRequest) WithLimit

WithLimit sets the maximum number of results.

func (*ReverseGeocodingRequest) WithType

WithType sets the location type filter.

type Route

type Route struct {
	Distance      float64    `json:"distance"`
	DistanceUnits string     `json:"distance_units,omitempty"`
	Time          float64    `json:"time"`
	Toll          bool       `json:"toll,omitempty"`
	Ferry         bool       `json:"ferry,omitempty"`
	Legs          []RouteLeg `json:"legs"`
}

Route represents a single route result.

type RouteDetail

type RouteDetail string

RouteDetail represents additional route detail types.

const (
	DetailInstructions RouteDetail = "instruction_details"
	DetailRoute        RouteDetail = "route_details"
	DetailElevation    RouteDetail = "elevation"
)

type RouteLeg

type RouteLeg struct {
	Distance       float64     `json:"distance"`
	Time           float64     `json:"time"`
	Steps          []LegStep   `json:"steps"`
	Elevation      []float64   `json:"elevation,omitempty"`
	ElevationRange [][]float64 `json:"elevation_range,omitempty"`
	CountryCode    []string    `json:"country_code,omitempty"`
}

RouteLeg represents a leg of a route.

type RouteMatrixAvoid

type RouteMatrixAvoid struct {
	Type   string     `json:"type"`
	Values []Location `json:"values,omitempty"`
}

RouteMatrixAvoid represents an area or feature to avoid.

type RouteMatrixEntry

type RouteMatrixEntry struct {
	Distance    float64 `json:"distance"`
	Time        float64 `json:"time"`
	SourceIndex int     `json:"source_index"`
	TargetIndex int     `json:"target_index"`
}

RouteMatrixEntry represents a single source-to-target result.

type RouteMatrixRequest

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

RouteMatrixRequest is a builder for route matrix API requests.

func (*RouteMatrixRequest) Do

Do executes the route matrix request.

func (*RouteMatrixRequest) Sources

func (r *RouteMatrixRequest) Sources(locations ...Location) *RouteMatrixRequest

Sources sets the source locations.

func (*RouteMatrixRequest) Targets

func (r *RouteMatrixRequest) Targets(locations ...Location) *RouteMatrixRequest

Targets sets the target locations.

func (*RouteMatrixRequest) WithAvoid

func (r *RouteMatrixRequest) WithAvoid(avoids ...RouteMatrixAvoid) *RouteMatrixRequest

WithAvoid sets areas or features to avoid.

func (*RouteMatrixRequest) WithMaxSpeed

func (r *RouteMatrixRequest) WithMaxSpeed(n int) *RouteMatrixRequest

WithMaxSpeed sets the maximum speed in km/h.

func (*RouteMatrixRequest) WithMode

WithMode sets the travel mode.

func (*RouteMatrixRequest) WithTraffic

WithTraffic sets the traffic model.

func (*RouteMatrixRequest) WithType

WithType sets the route optimization type.

func (*RouteMatrixRequest) WithUnits

func (r *RouteMatrixRequest) WithUnits(u Units) *RouteMatrixRequest

WithUnits sets the distance units.

type RouteMatrixResponse

type RouteMatrixResponse struct {
	Sources          []RouteMatrixWaypoint `json:"sources"`
	Targets          []RouteMatrixWaypoint `json:"targets"`
	SourcesToTargets [][]RouteMatrixEntry  `json:"sources_to_targets"`
}

RouteMatrixResponse is the response from the route matrix API.

type RouteMatrixService

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

RouteMatrixService provides access to the GeoApify Route Matrix API.

func (*RouteMatrixService) Calculate

func (s *RouteMatrixService) Calculate() *RouteMatrixRequest

Calculate creates a new route matrix request builder.

type RouteMatrixWaypoint

type RouteMatrixWaypoint struct {
	OriginalLocation [2]float64 `json:"original_location"`
	Location         [2]float64 `json:"location"`
}

RouteMatrixWaypoint represents a snapped waypoint in the matrix response.

type RoutePlannerRequest

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

RoutePlannerRequest is a builder for route planner API requests.

func (*RoutePlannerRequest) Do

Do executes the route planner request.

func (*RoutePlannerRequest) WithAgents

func (r *RoutePlannerRequest) WithAgents(agents ...PlannerAgent) *RoutePlannerRequest

WithAgents sets the agents (vehicles/drivers).

func (*RoutePlannerRequest) WithAvoid

func (r *RoutePlannerRequest) WithAvoid(avoids ...RouteMatrixAvoid) *RoutePlannerRequest

WithAvoid sets areas or features to avoid.

func (*RoutePlannerRequest) WithJobs

func (r *RoutePlannerRequest) WithJobs(jobs ...PlannerJob) *RoutePlannerRequest

WithJobs sets the jobs to be assigned.

func (*RoutePlannerRequest) WithLocations

func (r *RoutePlannerRequest) WithLocations(locations ...PlannerLocation) *RoutePlannerRequest

WithLocations sets the reusable locations.

func (*RoutePlannerRequest) WithMaxSpeed

func (r *RoutePlannerRequest) WithMaxSpeed(n int) *RoutePlannerRequest

WithMaxSpeed sets the maximum speed in km/h.

func (*RoutePlannerRequest) WithMode

WithMode sets the travel mode.

func (*RoutePlannerRequest) WithShipments

func (r *RoutePlannerRequest) WithShipments(shipments ...PlannerShipment) *RoutePlannerRequest

WithShipments sets the shipments to be assigned.

func (*RoutePlannerRequest) WithTraffic

WithTraffic sets the traffic model.

func (*RoutePlannerRequest) WithType

WithType sets the route optimization type.

func (*RoutePlannerRequest) WithUnits

WithUnits sets the distance units.

type RoutePlannerResponse

type RoutePlannerResponse struct {
	Properties map[string]any       `json:"properties,omitempty"`
	Agents     []PlannerAgentResult `json:"agents,omitempty"`
}

RoutePlannerResponse is the response from the route planner API.

type RoutePlannerService

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

RoutePlannerService provides access to the GeoApify Route Planner (VRP) API.

func (*RoutePlannerService) Plan

Plan creates a new route planner request builder.

type RouteType

type RouteType string

RouteType represents a route optimization type.

const (
	RouteBalanced      RouteType = "balanced"
	RouteShort         RouteType = "short"
	RouteLessManeuvers RouteType = "less_maneuvers"
)

type RoutingRequest

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

RoutingRequest is a builder for routing API requests.

func (*RoutingRequest) Do

Do executes the routing request.

func (*RoutingRequest) WithAvoid

func (r *RoutingRequest) WithAvoid(avoids ...string) *RoutingRequest

WithAvoid sets road features to avoid.

func (*RoutingRequest) WithDetails

func (r *RoutingRequest) WithDetails(details ...RouteDetail) *RoutingRequest

WithDetails sets additional route details to include.

func (*RoutingRequest) WithFormat

func (r *RoutingRequest) WithFormat(f Format) *RoutingRequest

WithFormat sets the response format.

func (*RoutingRequest) WithLang

func (r *RoutingRequest) WithLang(v string) *RoutingRequest

WithLang sets the response language.

func (*RoutingRequest) WithMaxSpeed

func (r *RoutingRequest) WithMaxSpeed(n int) *RoutingRequest

WithMaxSpeed sets the maximum speed in km/h.

func (*RoutingRequest) WithMode

func (r *RoutingRequest) WithMode(mode TravelMode) *RoutingRequest

WithMode sets the travel mode.

func (*RoutingRequest) WithTraffic

func (r *RoutingRequest) WithTraffic(t TrafficModel) *RoutingRequest

WithTraffic sets the traffic model.

func (*RoutingRequest) WithType

func (r *RoutingRequest) WithType(t RouteType) *RoutingRequest

WithType sets the route optimization type.

func (*RoutingRequest) WithUnits

func (r *RoutingRequest) WithUnits(u Units) *RoutingRequest

WithUnits sets the distance units.

type RoutingResponse

type RoutingResponse struct {
	Results    []Route        `json:"results"`
	Properties map[string]any `json:"properties,omitempty"`
}

RoutingResponse is the response from the routing API.

type RoutingService

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

RoutingService provides access to the GeoApify Routing API.

func (*RoutingService) Waypoints

func (s *RoutingService) Waypoints(waypoints ...Location) *RoutingRequest

Waypoints creates a new routing request builder with the given waypoints.

type SearchRequest

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

SearchRequest is a builder for forward geocoding requests.

func (*SearchRequest) Do

Do executes the forward geocoding request.

func (*SearchRequest) WithBias

func (r *SearchRequest) WithBias(biases ...string) *SearchRequest

WithBias adds geocoding biases (joined with |).

func (*SearchRequest) WithCity

func (r *SearchRequest) WithCity(v string) *SearchRequest

WithCity sets the city parameter.

func (*SearchRequest) WithCountry

func (r *SearchRequest) WithCountry(v string) *SearchRequest

WithCountry sets the country parameter.

func (*SearchRequest) WithFilter

func (r *SearchRequest) WithFilter(filters ...string) *SearchRequest

WithFilter adds geocoding filters (joined with |).

func (*SearchRequest) WithFormat

func (r *SearchRequest) WithFormat(f Format) *SearchRequest

WithFormat sets the response format.

func (*SearchRequest) WithHouseNumber

func (r *SearchRequest) WithHouseNumber(v string) *SearchRequest

WithHouseNumber sets the house number parameter.

func (*SearchRequest) WithLang

func (r *SearchRequest) WithLang(v string) *SearchRequest

WithLang sets the response language.

func (*SearchRequest) WithLimit

func (r *SearchRequest) WithLimit(n int) *SearchRequest

WithLimit sets the maximum number of results.

func (*SearchRequest) WithName

func (r *SearchRequest) WithName(v string) *SearchRequest

WithName sets the name parameter.

func (*SearchRequest) WithPostcode

func (r *SearchRequest) WithPostcode(v string) *SearchRequest

WithPostcode sets the postcode parameter.

func (*SearchRequest) WithState

func (r *SearchRequest) WithState(v string) *SearchRequest

WithState sets the state parameter.

func (*SearchRequest) WithStreet

func (r *SearchRequest) WithStreet(v string) *SearchRequest

WithStreet sets the street parameter.

func (*SearchRequest) WithType

func (r *SearchRequest) WithType(t LocationType) *SearchRequest

WithType sets the location type filter.

type StepInstruction

type StepInstruction struct {
	Text string `json:"text,omitempty"`
	Type string `json:"type,omitempty"`
}

StepInstruction contains turn-by-turn instruction details.

type Timezone

type Timezone struct {
	Name             string `json:"name,omitempty"`
	NameAlt          string `json:"name_alt,omitempty"`
	OffsetSTD        string `json:"offset_STD,omitempty"`
	OffsetSTDSeconds int    `json:"offset_STD_seconds,omitempty"`
	OffsetDST        string `json:"offset_DST,omitempty"`
	OffsetDSTSeconds int    `json:"offset_DST_seconds,omitempty"`
	AbbreviationSTD  string `json:"abbreviation_STD,omitempty"`
	AbbreviationDST  string `json:"abbreviation_DST,omitempty"`
}

Timezone contains timezone information.

type TrafficModel

type TrafficModel string

TrafficModel represents a traffic model.

const (
	TrafficFreeFlow     TrafficModel = "free_flow"
	TrafficApproximated TrafficModel = "approximated"
)

type TravelMode

type TravelMode string

TravelMode represents a travel/transportation mode.

const (
	ModeDrive               TravelMode = "drive"
	ModeLightTruck          TravelMode = "light_truck"
	ModeMediumTruck         TravelMode = "medium_truck"
	ModeTruck               TravelMode = "truck"
	ModeHeavyTruck          TravelMode = "heavy_truck"
	ModeTruckDangerousGoods TravelMode = "truck_dangerous_goods"
	ModeLongTruck           TravelMode = "long_truck"
	ModeBus                 TravelMode = "bus"
	ModeScooter             TravelMode = "scooter"
	ModeMotorcycle          TravelMode = "motorcycle"
	ModeBicycle             TravelMode = "bicycle"
	ModeMountainBike        TravelMode = "mountain_bike"
	ModeRoadBike            TravelMode = "road_bike"
	ModeWalk                TravelMode = "walk"
	ModeHike                TravelMode = "hike"
	ModeTransit             TravelMode = "transit"
	ModeApproximatedTransit TravelMode = "approximated_transit"
)

type Units

type Units string

Units represents distance units.

const (
	UnitsMetric   Units = "metric"
	UnitsImperial Units = "imperial"
)

Jump to

Keyboard shortcuts

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