> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coreflux.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Google Routes

> LoT connector for the Google Routes API: compute routes with ETAs and route matrices between origins and destinations from MQTT requests

Technical Preview

## Overview

Client-mode REST API connectors for Google Maps Platform: geocoding, elevation, time zone, device geolocation, Routes API ETAs and matrices, Roads API snap to roads and speed limits, Places search, Address Validation, Weather and Air Quality.

This is one of the templates in the Google Maps Platform REST API app (`google-maps-platform`). Deploy it alongside the other connectors of that app when they depend on each other (for example a token connector plus an API connector).

## Auth

* **schemes**: \["API key query parameter key= (Geocoding, Elevation, Time Zone, Geolocation, Roads, Address Validation, Weather, Air Quality)", "X-Goog-Api-Key header + required X-Goog-FieldMask header (Routes API, Places API (New))"]
* **secrets**: \["GOOGLE\_MAPS\_API\_KEY"]
* **note**: OAuth 2.0 service accounts not packaged (Fleet Engine and Route Optimization need OAuth).

Auth headers used by the template: `X-Goog-Api-Key: {value.json.apikey}`.

## Template parameters

| Placeholder | Type | Description | Required |
| - | - | - | - |
| `RouteName` | string | Name of the Google Routes connector | no |
| `BaseUrl` | string | Google Routes base URL without trailing slash (e.g. [https://routes.googleapis.com](https://routes.googleapis.com)) | yes |

`BASE_ADDRESS` default: `https://routes.googleapis.com`.

## Events

| Event | Method | Endpoint | Request topic | Response topic | Payload fields |
| - | - | - | - | - | - |
| `ComputeRoutes` | POST | `/directions/v2:computeRoutes` | `fleet/google-maps/routes/compute` | `fleet/google-maps/routes/compute/response` | `apikey`, `body`, `fieldmask` |
| `ComputeRouteMatrix` | POST | `/distanceMatrix/v2:computeRouteMatrix` | `fleet/google-maps/routes/matrix` | `fleet/google-maps/routes/matrix/response` | `apikey`, `body`, `fieldmask` |

## Deploy

Get the template card (JSON with `template` and `metadata`) from the broker, then deploy the connector:

```bash theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
mosquitto_pub -t '$SYS/Coreflux/Command' -m "-connectorCode GOOGLE_ROUTES"
```

The deployable connector from the REST API app, with `BASE_ADDRESS` already filled in:

```lot theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
DEFINE CONNECTOR GoogleRoutes WITH TYPE REST_API
    ADD REST_API_CONFIG
        WITH BASE_ADDRESS "https://routes.googleapis.com"
        WITH ENABLE_CLIENT "true"
        WITH USE_SSL "true"
        WITH REQUEST_TIMEOUT '30'
        WITH DEFAULT_CONTENT_TYPE "application/json"
    ADD EVENT ComputeRoutes
        WITH SOURCE_TOPIC "fleet/google-maps/routes/compute"
        WITH DESTINATION_TOPIC "fleet/google-maps/routes/compute/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/directions/v2:computeRoutes"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "User-Agent" "Coreflux-Broker REST_API route (https://www.coreflux.org)"
            ADD "X-Goog-Api-Key" "{value.json.apikey}"
            ADD "X-Goog-FieldMask" "{value.json.fieldmask}"
            ADD "Content-Type" "application/json"
        WITH BODY "{value.json.body}"
    ADD EVENT ComputeRouteMatrix
        WITH SOURCE_TOPIC "fleet/google-maps/routes/matrix"
        WITH DESTINATION_TOPIC "fleet/google-maps/routes/matrix/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/distanceMatrix/v2:computeRouteMatrix"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "User-Agent" "Coreflux-Broker REST_API route (https://www.coreflux.org)"
            ADD "X-Goog-Api-Key" "{value.json.apikey}"
            ADD "X-Goog-FieldMask" "{value.json.fieldmask}"
            ADD "Content-Type" "application/json"
        WITH BODY "{value.json.body}"
```

Deploy it with `-addConnector` (do not include `ADD METADATA`).

## Usage example

Call `ComputeRoutes` by publishing a JSON payload to its request topic, and read the reply on the response topic:

```bash theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
mosquitto_sub -t 'fleet/google-maps/routes/compute/response' &
mosquitto_pub -t 'fleet/google-maps/routes/compute' -m '{"apikey": "<apikey>", "body": {}, "fieldmask": "<fieldmask>"}'
```

## Related

* [REST API Connectors](https://docs.coreflux.org/latest/connectors/rest-api/overview)
* [REST API Apps catalog](https://docs.coreflux.org/latest/connectors/rest-api-apps)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.