> ## 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 Roads

> LoT connector for the Google Roads API: snap GPS points to roads, find the nearest roads, and look up speed limits along a path 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).

## Template parameters

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

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

## Events

| Event | Method | Endpoint | Request topic | Response topic | Payload fields |
| - | - | - | - | - | - |
| `SnapToRoads` | GET | `/v1/snapToRoads?key={value.json.apikey}&path={value.json.path}{value.json.params}` | `fleet/google-maps/roads/snap` | `fleet/google-maps/roads/snap/response` | `apikey`, `params`, `path` |
| `NearestRoads` | GET | `/v1/nearestRoads?key={value.json.apikey}&points={value.json.points}` | `fleet/google-maps/roads/nearest` | `fleet/google-maps/roads/nearest/response` | `apikey`, `points` |
| `SpeedLimits` | GET | `/v1/speedLimits?key={value.json.apikey}&path={value.json.path}{value.json.params}` | `fleet/google-maps/roads/speedlimits` | `fleet/google-maps/roads/speedlimits/response` | `apikey`, `params`, `path` |

## 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_ROADS"
```

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 GoogleRoads WITH TYPE REST_API
    ADD REST_API_CONFIG
        WITH BASE_ADDRESS "https://roads.googleapis.com"
        WITH ENABLE_CLIENT "true"
        WITH USE_SSL "true"
        WITH REQUEST_TIMEOUT '30'
        WITH DEFAULT_CONTENT_TYPE "application/json"
    ADD EVENT SnapToRoads
        WITH SOURCE_TOPIC "fleet/google-maps/roads/snap"
        WITH DESTINATION_TOPIC "fleet/google-maps/roads/snap/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/v1/snapToRoads?key={value.json.apikey}&path={value.json.path}{value.json.params}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "User-Agent" "Coreflux-Broker REST_API route (https://www.coreflux.org)"
    ADD EVENT NearestRoads
        WITH SOURCE_TOPIC "fleet/google-maps/roads/nearest"
        WITH DESTINATION_TOPIC "fleet/google-maps/roads/nearest/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/v1/nearestRoads?key={value.json.apikey}&points={value.json.points}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "User-Agent" "Coreflux-Broker REST_API route (https://www.coreflux.org)"
    ADD EVENT SpeedLimits
        WITH SOURCE_TOPIC "fleet/google-maps/roads/speedlimits"
        WITH DESTINATION_TOPIC "fleet/google-maps/roads/speedlimits/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/v1/speedLimits?key={value.json.apikey}&path={value.json.path}{value.json.params}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "User-Agent" "Coreflux-Broker REST_API route (https://www.coreflux.org)"
```

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

## Usage example

Call `SnapToRoads` 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/roads/snap/response' &
mosquitto_pub -t 'fleet/google-maps/roads/snap' -m '{"apikey": "<apikey>", "params": "<params>", "path": "<path>"}'
```

## Related

* [REST API Connectors](https://docs.coreflux.org/v2.22/lot-language/routes/rest-api-routes.md)
* [REST API Apps catalog](https://docs.coreflux.org/v2.22/lot-language/routes/rest-api-apps.md)


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