ReqValhalla (ReqValhalla v0.3.0)
View SourceAn Elixir client for the Valhalla routing API using Req.
This module provides a simple interface to interact with Valhalla's routing services, including routing, isochrones, matrices, and more.
Configuration
You can configure the base URL and default Req options for the Valhalla service:
config :req_valhalla,
base_url: "http://your-valhalla-instance.com",
req_options: [receive_timeout: 60_000]Examples
# Create a route between two points
locations = [%{lat: 48.8566, lon: 2.3522}, %{lat: 48.8698, lon: 2.3467}]
{:ok, response} = ReqValhalla.route(locations, costing: "auto")
# Get an isochrone
location = %{lat: 48.8566, lon: 2.3522}
{:ok, response} = ReqValhalla.isochrone(
location,
contours: [%{time: 10}, %{time: 20}],
costing: "pedestrian"
)
Summary
Functions
Gets the configured base URL for the Valhalla service.
Gets elevation data for a set of locations or a path.
Generates an isochrone (time-distance polygon) from a location.
Finds the nearest roads to the given location(s).
Computes a time-distance matrix for multiple origin and destination pairs.
Computes an optimized route visiting all locations.
Makes a POST request to the Valhalla API.
Calculates a route between multiple locations.
Checks the status of the Valhalla service.
Gets attributes along a path matched to the road network.
Matches a GPS trace to the road network.
Functions
Gets the configured base URL for the Valhalla service.
Gets elevation data for a set of locations or a path.
Parameters
shape: List of location maps with:latand:lonkeysopts: Additional options
Examples
iex> shape = [%{lat: 48.8566, lon: 2.3522}, %{lat: 48.8698, lon: 2.3467}]
iex> {:ok, response} = ReqValhalla.height(shape)
iex> is_map(response)
true
Generates an isochrone (time-distance polygon) from a location.
Parameters
location: A location map with:latand:lonkeysopts: Options including:contours,:costing, etc.
Options
:contours- List of contour maps with:time(in minutes) or:distancekeys:costing- The costing model (default: "auto"):polygons- Whether to return polygons (default: true):denoise- Remove small contours (default: 1.0):generalize- Generalize the contours (default: based on meters):req_options- Additional Req options (e.g.,[receive_timeout: 60_000])
Examples
iex> location = %{lat: 48.8566, lon: 2.3522}
iex> {:ok, response} = ReqValhalla.isochrone(
...> location,
...> contours: [%{time: 10}, %{time: 20}, %{time: 30}],
...> costing: "pedestrian"
...> )
iex> is_map(response)
true
Finds the nearest roads to the given location(s).
Parameters
locations: A single location map or list of location maps with:latand:lonkeysopts: Additional options
Examples
iex> location = %{lat: 48.8566, lon: 2.3522}
iex> {:ok, response} = ReqValhalla.locate(location)
iex> is_list(response) or is_map(response)
true
Computes a time-distance matrix for multiple origin and destination pairs.
Parameters
sources: List of source location mapstargets: List of target location mapsopts: Options including:costing,:units, etc.
Options
:costing- The costing model (default: "auto"):units- Distance units (default: "kilometers"):req_options- Additional Req options (e.g.,[receive_timeout: 60_000])
Examples
iex> sources = [%{lat: 48.8566, lon: 2.3522}]
iex> targets = [%{lat: 48.8698, lon: 2.3467}, %{lat: 48.8606, lon: 2.3376}]
iex> {:ok, response} = ReqValhalla.matrix(sources, targets, costing: "auto")
iex> is_map(response)
true
Computes an optimized route visiting all locations.
Parameters
locations: List of location maps to visitopts: Options including:costing,:units, etc.
Examples
iex> locations = [
...> %{lat: 48.8566, lon: 2.3522},
...> %{lat: 48.8698, lon: 2.3467},
...> %{lat: 48.8606, lon: 2.3376}
...> ]
iex> {:ok, response} = ReqValhalla.optimized_route(locations, costing: "auto")
iex> is_map(response)
true
Makes a POST request to the Valhalla API.
Parameters
endpoint: The API endpoint (e.g., "route", "isochrone")params: The request parameters as a mapopts: Optional keyword list of Req options (e.g.,receive_timeout: 60_000)
Returns
{:ok, response}on success{:error, exception}on failure
Calculates a route between multiple locations.
Parameters
locations: A list of location maps with:latand:lonkeysopts: Additional options such as:costing,:units,:directions_options, etc.
Options
:costing- The costing model: "auto", "bicycle", "pedestrian", "truck", etc. (default: "auto"):units- Distance units: "kilometers" or "miles" (default: "kilometers"):language- Language for instructions (default: "en-US"):directions_options- Options for turn-by-turn directions:exclude_locations- Locations to exclude from the route:date_time- Departure or arrival time information:req_options- Additional Req options (e.g.,[receive_timeout: 60_000])
Examples
iex> locations = [%{lat: 48.8566, lon: 2.3522}, %{lat: 48.8698, lon: 2.3467}]
iex> {:ok, response} = ReqValhalla.route(locations, costing: "auto")
iex> is_map(response)
true
Checks the status of the Valhalla service.
Examples
iex> {:ok, status} = ReqValhalla.status()
iex> is_map(status)
true
Gets attributes along a path matched to the road network.
Parameters
shape: List of GPS points with:latand:lonkeysopts: Options including:costing,:filters, etc.
Examples
iex> shape = [
...> %{lat: 48.8566, lon: 2.3522},
...> %{lat: 48.8698, lon: 2.3467}
...> ]
iex> {:ok, response} = ReqValhalla.trace_attributes(shape, costing: "auto")
iex> is_map(response)
true
Matches a GPS trace to the road network.
Parameters
shape: List of GPS points with:latand:lonkeysopts: Options including:costing,:shape_match, etc.
Examples
iex> shape = [
...> %{lat: 48.8566, lon: 2.3522},
...> %{lat: 48.8570, lon: 2.3525},
...> %{lat: 48.8698, lon: 2.3467}
...> ]
iex> {:ok, response} = ReqValhalla.trace_route(shape, costing: "auto")
iex> is_map(response)
true