Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Map providers

Waylingo supports two map providers, TomTom and HERE. An app uses exactly one, chosen in its configuration. There is no mixing and no fallback from one to the other.

Why one provider per app: detour times subtract travel times, and times from two providers’ traffic models cannot be meaningfully subtracted. Mixing would also need several keys per app and could conflict with providers’ terms about combining their content.

The adapter trait

Each provider is a ProviderAdapter (crates/waylingo-providers/src/types.rs). Every method is pure: it builds an HttpRequest or parses an HttpResponse. Adapters never send anything and never hold a key.

#![allow(unused)]
fn main() {
pub trait ProviderAdapter {
    fn kind(&self) -> ProviderKind;
    fn capabilities(&self) -> Capabilities;
    fn attribution(&self) -> &'static str;
    fn setup_requests(&self, id_prefix: &str) -> Vec<HttpRequest>;
    fn apply_setup(&mut self, resp: &HttpResponse) -> Result<(), ProviderError>;
    fn geocode_request(&self, id: String, query: &str, bias: Option<LatLng>) -> HttpRequest;
    fn parse_geocode(&self, resp: &HttpResponse) -> Result<Vec<GeocodeCandidate>, ProviderError>;
    fn route_request(&self, id: String, q: &RouteQuery) -> HttpRequest;
    fn parse_route(&self, resp: &HttpResponse) -> Result<RouteResult, ProviderError>;
    fn search_request(&self, id: String, q: &SearchQuery) -> HttpRequest;
    fn parse_search(&self, resp: &HttpResponse) -> Result<Vec<Candidate>, ProviderError>;
    fn matrix_request(/* ... */) -> Option<HttpRequest> { None }
    fn parse_matrix(/* ... */) -> Result<Vec<Option<f64>>, ProviderError> { /* unsupported */ }
}
}

A parsed route is a RouteResult: a MeasuredRoute (see Routing and stops), the distance at the end of each leg, and the provider’s traffic delay. A search result is a list of Candidates with an id, name, position, address, brand and, where known, detour time and distance. Everything an adapter parses is provider content: it goes into the GeoJSON output only. The provider crate does not depend on the LLM crate, and scripts/check_deps.sh fails CI if either ever depends on the other.

Capabilities tells the engine how to get detour times (Native or Matrix), the most route points one search accepts, and the most results one search returns. It also lists filter and avoid support, which is published as a support matrix; the engine reads only the detour strategy and the two limits.

ProviderKind and DetourStrategy also have Google values (Google, FromRoutingSummaries), left from the original design. There is no Google adapter.

TomTom and HERE compared

TomTom (tomtom.rs)HERE (here.rs)
RoutingRouting API v1 calculateRoute, GET, traffic=true, travelMode=carRouting v8 routes, GET, return=polyline,summary,actions, via for intermediate points
Route timingguidance instructionssection actions
GeocodingSearch v2 geocode, 5 results, biased to the current locationGeocoding v1 geocode, 5 results, at= the current location
Along-route searchSearch v2 searchAlongRoute, POST with the window’s pointsBrowse (category only) or Discover (brand or free text), GET with route=<flexible polyline>;w=<metres>
Search limit20 results, 250 route points100 results, 120 route points
Search boundmaxDetourTimecorridor width w (the anchor radius)
Detour timesin the search results (detourTime)one Matrix v8 call per stop (async=false)
Category idsfetched once per session from poiCategories and matched by name and synonymsfixed table of HERE category ids
Charger power filterminPowerKWevStation[minPower] (category searches only)
Connector filterconnectorSetnot supported
AvoidtollRoads, motorways, ferriesavoid[features]=tollRoad,controlledAccessHighway,ferry
Electric vehicle flag on routesvehicleEngineType=electricnot sent
Departure timedepartAtdepartureTime
Keyquery parameter keyquery parameter apiKey
Attribution© TomTom© HERE

Notes from the code:

  • TomTom’s category list is the only setup request. It is made only when the plan has stops. If it fails, the result gets a warning and searches use text only.
  • TomTom and brands. A brand is sent as the search text, not as brandSet, because brandSet only knows chains in TomTom’s brand registry. As text, a local name (“Cafe de Jaren”) and a misspelt chain (“macdonalds”) are both found.
  • TomTom and categories. A category stop without a brand sends * plus the categorySet id, because generic text together with categorySet returned nothing in live tests. A brand with a category (“a Shell petrol station”) sends the brand as the text plus categorySet, which works (search_request in tomtom.rs).
  • HERE and detours. HERE’s along-route search reports a distance off the route (excursionDistance, kept as detour_m), not a time. Ranking by distance off the road would prefer a place that is close but slow to reach, so the engine asks for a travel-time matrix (see Detour time).
  • HERE’s URL length. The corridor is encoded into a GET URL; 120 route points keeps it under HERE’s 2,048-byte guidance.

Both adapters set an 8-second timeout_ms hint on every request.

Errors from providers

ProviderError::from_status (crates/waylingo-providers/src/error.rs) classifies a failed response:

ResponseKindCode in the result
401, 403AuthPROVIDER_AUTH
402QuotaExceededPROVIDER_QUOTA_EXCEEDED
429RateLimitedPROVIDER_RATE_LIMITED
other 4xxBadRequestPROVIDER_BAD_REQUEST
5xxUpstreamPROVIDER_UNAVAILABLE
no responseTransportPROVIDER_UNREACHABLE
2xx that does not parseBadResponsePROVIDER_BAD_RESPONSE
route reply with no routeNoRouteNO_ROUTE

TomTom also answers 403 for some over-limit cases, so a used-up TomTom quota can appear as PROVIDER_AUTH. The message includes the provider’s own error text (HERE title and cause, TomTom errorText, and so on), cut to 300 characters, with words that look like keys (key=, apikey=, or longer than 40 characters) masked. URLs are never put in messages, because a URL may carry a key.

Keys and proxies

The engine emits requests with credential: Map (or Llm) and an auth placement. The host adds the key at send time. In waylingo-reqwest this happens in one place, prepare in crates/waylingo-reqwest/src/wire.rs: a query-parameter key is percent-encoded and appended to the URL, a header key is added with its prefix, and an empty key adds nothing (a local LLM server needs none). Keys prints as <redacted>. Errors from the hosts never include URLs.

A key shipped inside an app can be extracted, so the bindings support proxies:

  • Map proxy. ProviderChoice::TomTom { base_url } replaces https://api.tomtom.com. ProviderChoice::Here { base_url } routes every HERE service through {base}/router, {base}/geocode, {base}/browse, {base}/discover and {base}/matrix. The proxy adds the real key; the app’s map key may be empty or carry the proxy’s own token.
  • LLM proxy. Give the LLM backend a base_url; the LLM key may then be left out.

Attribution and terms

Every result carries the provider’s attribution string, which must be shown with the results. Each developer’s use of a provider is governed by their own agreement with that provider; Waylingo does not check it.