Geofox (geofox_ex v0.1.0)

View Source

Public API for interacting with the HVV Geofox API.

This module provides an interface to all Geofox API functionality including:

  • Route planning and individual routing
  • Station and line information
  • Real-time departures and announcements
  • Tariff calculation and ticket optimization
  • Vehicle tracking and map data

Summary

Functions

Create a bounding box from two coordinates.

Search for stations, addresses, or points of interest by name.

Check if a postal code is within the HVV service area.

Create a coordinate structure.

Get the complete course/schedule of a specific departure.

Get departure information for a station.

Get service announcements and disruption information.

Get individual routes (walking, cycling) between multiple start and destination points.

Get public transport routes between two locations.

Get detailed information about a station including elevators and accessibility.

Calculate tariff information for a given route.

Get track coordinates for specific stop points.

Get vehicle positions and movements within a bounding box.

Create a GTI time structure.

Create a GTI time structure from an Elixir DateTime.

Initialize a session with the Geofox API to get service information and validate connectivity.

List all available lines with optional subline information.

List all available stations.

Get list of available tickets.

Create a new Geofox client.

Optimize ticket selection for a single journey.

Create a station/location structure.

Get tariff metadata including available zones, counties, and tariff types.

Get information about neighboring tariff zones.

Functions

bounding_box(lower_left, upper_right)

@spec bounding_box(map(), map()) :: map()

Create a bounding box from two coordinates.

check_name(client, name, opts \\ [])

@spec check_name(Geofox.Client.t(), Geofox.Types.sd_name(), keyword()) ::
  {:ok, map()} | {:error, term()}

Search for stations, addresses, or points of interest by name.

check_postal_code(client, postal_code, opts \\ [])

@spec check_postal_code(Geofox.Client.t(), integer(), keyword()) ::
  {:ok, map()} | {:error, term()}

Check if a postal code is within the HVV service area.

coordinate(x, y, type \\ "EPSG_4326")

@spec coordinate(number(), number(), String.t()) :: map()

Create a coordinate structure.

Examples

iex> Geofox.coordinate(53.5511, 9.9937)
%{"x" => 53.5511, "y" => 9.9937, "type" => "EPSG_4326"}

departure_course(client, line_key, station, time, opts \\ [])

@spec departure_course(
  Geofox.Client.t(),
  String.t(),
  Geofox.Types.sd_name(),
  String.t(),
  keyword()
) ::
  {:ok, map()} | {:error, term()}

Get the complete course/schedule of a specific departure.

departure_list(client, station, time, opts \\ [])

@spec departure_list(
  Geofox.Client.t(),
  Geofox.Types.sd_name(),
  Geofox.Types.gti_time(),
  keyword()
) ::
  {:ok, map()} | {:error, term()}

Get departure information for a station.

Examples

station = Geofox.station("Hauptbahnhof", "Master:1")
time = Geofox.gti_time("2024-01-15", "14:30")

{:ok, departures} = Geofox.departure_list(client, station, time)

get_announcements(client, opts \\ [])

@spec get_announcements(
  Geofox.Client.t(),
  keyword()
) :: {:ok, map()} | {:error, term()}

Get service announcements and disruption information.

get_individual_route(client, starts, dests, opts \\ [])

@spec get_individual_route(
  Geofox.Client.t(),
  [Geofox.Types.sd_name()],
  [Geofox.Types.sd_name()],
  keyword()
) :: {:ok, map()} | {:error, term()}

Get individual routes (walking, cycling) between multiple start and destination points.

get_route(client, start, dest, time, opts \\ [])

@spec get_route(
  Geofox.Client.t(),
  Geofox.Types.sd_name(),
  Geofox.Types.sd_name(),
  Geofox.Types.gti_time(),
  keyword()
) :: {:ok, map()} | {:error, term()}

Get public transport routes between two locations.

Examples

start = Geofox.station("Hauptbahnhof", "Master:1")
dest = Geofox.station("Flughafen", "Master:3690")
time = Geofox.gti_time("2024-01-15", "14:30")

{:ok, routes} = Geofox.get_route(client, start, dest, time)

get_station_information(client, station, opts \\ [])

@spec get_station_information(Geofox.Client.t(), Geofox.Types.sd_name(), keyword()) ::
  {:ok, map()} | {:error, term()}

Get detailed information about a station including elevators and accessibility.

get_tariff(client, schedule_elements, departure, arrival, opts \\ [])

@spec get_tariff(
  Geofox.Client.t(),
  [map()],
  Geofox.Types.gti_time(),
  Geofox.Types.gti_time(),
  keyword()
) :: {:ok, map()} | {:error, term()}

Calculate tariff information for a given route.

get_track_coordinates(client, stop_point_keys, opts \\ [])

@spec get_track_coordinates(Geofox.Client.t(), [String.t()], keyword()) ::
  {:ok, map()} | {:error, term()}

Get track coordinates for specific stop points.

get_vehicle_map(client, bounding_box, opts \\ [])

@spec get_vehicle_map(Geofox.Client.t(), Geofox.Types.bounding_box(), keyword()) ::
  {:ok, map()} | {:error, term()}

Get vehicle positions and movements within a bounding box.

gti_time(date, time)

@spec gti_time(String.t(), String.t()) :: map()

Create a GTI time structure.

Examples

iex> Geofox.gti_time("2024-01-15", "14:30")
%{"date" => "2024-01-15", "time" => "14:30"}

gti_time_from_datetime(datetime)

@spec gti_time_from_datetime(DateTime.t()) :: map()

Create a GTI time structure from an Elixir DateTime.

init(client, opts \\ [])

@spec init(
  Geofox.Client.t(),
  keyword()
) :: {:ok, map()} | {:error, term()}

Initialize a session with the Geofox API to get service information and validate connectivity.

list_lines(client, opts \\ [])

@spec list_lines(
  Geofox.Client.t(),
  keyword()
) :: {:ok, map()} | {:error, term()}

List all available lines with optional subline information.

list_stations(client, opts \\ [])

@spec list_stations(
  Geofox.Client.t(),
  keyword()
) :: {:ok, map()} | {:error, term()}

List all available stations.

list_tickets(client, opts \\ [])

@spec list_tickets(
  Geofox.Client.t(),
  keyword()
) :: {:ok, map()} | {:error, term()}

Get list of available tickets.

new(opts \\ [])

@spec new(keyword()) :: Geofox.Client.t()

Create a new Geofox client.

Options

  • :base_url - Base URL for the API (default: "https://gti.geofox.de")
  • :timeout - Request timeout in milliseconds (default: 30000)
  • :headers - Additional headers to include in requests
  • :user - Username for authentication (if required)
  • :password - Password for authentication (if required)

Examples

iex> client = Geofox.new()
iex> client = Geofox.new(timeout: 60000)

single_ticket_optimizer(client, route, opts \\ [])

@spec single_ticket_optimizer(Geofox.Client.t(), map(), keyword()) ::
  {:ok, map()} | {:error, term()}

Optimize ticket selection for a single journey.

station(name, id \\ nil, opts \\ [])

@spec station(String.t(), String.t() | nil, keyword()) :: map()

Create a station/location structure.

Examples

iex> Geofox.station("Hauptbahnhof", "Master:1")
%{"name" => "Hauptbahnhof", "id" => "Master:1", "type" => "STATION"}

tariff_meta_data(client, opts \\ [])

@spec tariff_meta_data(
  Geofox.Client.t(),
  keyword()
) :: {:ok, map()} | {:error, term()}

Get tariff metadata including available zones, counties, and tariff types.

tariff_zone_neighbours(client, opts \\ [])

@spec tariff_zone_neighbours(
  Geofox.Client.t(),
  keyword()
) :: {:ok, map()} | {:error, term()}

Get information about neighboring tariff zones.