Valhalla

Main entry point for the Valhalla routing engine on Android.

This class provides a Kotlin interface to the native Valhalla C++ routing engine. It handles configuration management, JSON serialization, and routing requests.

One instance holds one native actor, including the mmapped tile extract, for its whole lifetime. Building it is expensive and happens during construction, so reuse a single instance across many requests. Call close when done — ideally through Kotlin's use { } — since nothing else releases the native actor.

There are two ways in, matching iOS's Valhalla(_:) and Valhalla(configPath:): hand it a ValhallaConfig to write out and use, or point it at a config file already on disk.

See also

Constructors

Link copied to clipboard
constructor(context: Context, config: ValhallaConfig, valhallaConfigManager: ValhallaConfigManager = ValhallaConfigManager(context), moshi: Moshi = defaultMoshi())

Writes config to the device, then builds the engine from it.

constructor(configPath: String, moshi: Moshi = defaultMoshi())

Builds the engine from a config file already on disk.

Functions

Link copied to clipboard
open override fun close()

Release the native actor held by this instance. Safe to call more than once.

Link copied to clipboard
fun height(request: HeightRequest): HeightResponse

Sample terrain heights under a shape, from the elevation tiles in the config's additionalData.elevation. Without them every height is null.

Link copied to clipboard
fun heightRaw(requestJson: String): String

Run a height request supplied as JSON and return the raw response.

Link copied to clipboard
fun matrix(request: MatrixRequest): MatrixResponse

Computes a matrix of costs and times between every source and every target.

Link copied to clipboard
fun matrixRaw(requestJson: String): String

Run a sources_to_targets request supplied as JSON and return the raw response.

Link copied to clipboard
fun route(request: RouteRequest): ValhallaResponse

Fetch a route from Valhalla.

Link copied to clipboard
fun routeRaw(requestJson: String): String

Run a route request supplied as JSON and return the raw response.

Link copied to clipboard
fun traceAttributes(request: TraceAttributesRequest): TraceAttributesResponse

Map-match a GPS trace onto the road network and return the attributes of every edge along the matched path.

Link copied to clipboard
fun traceAttributesRaw(requestJson: String): String

Run a trace_attributes request supplied as JSON and return the raw response.

Link copied to clipboard
fun traceRoute(request: MapMatchRequest): MapMatchRouteResponse

Map-match a GPS trace onto the road network and return a route along the matched path.

Link copied to clipboard
fun traceRouteRaw(requestJson: String): String

Run a trace_route request supplied as JSON and return the raw response.