To receive trip data updates from Google Maps or Waze, configure your backend
using one of the following options:

- A pull method using the Navigation Connect API, or
- An event-driven push method using Google Cloud Pub/Sub.

## Option 1: Use the Navigation Connect API

To manually fetch the latest trip status, call the `GetTrip` method with
the unique trip ID.

The following sample shows how to call the API from the command line using your
Application Default Credentials (ADC) to authorize the server-to-server
request.

```bash
#!/bin/bash

gcloud auth application-default login
access_token="$(gcloud auth application-default print-access-token)"

# Call the GetTrip method
curl -X GET "https://navigationconnect.googleapis.com/v1/projects/PROJECT_ID/trips/TRIP_ID" \
-H "Authorization: Bearer ${access_token}" \
-H "Content-Type: application/json"
```

> [!NOTE]
> **Note:** Use these script examples only for local testing and development. For production server-to-server calls, use [Account Default Credentials](https://cloud.google.com/docs/authentication/provide-credentials-adc) with a service account. To learn more about the underlying protocol, see [Using OAuth 2.0 to Access Google APIs](https://developers.google.com/identity/protocols/oauth2.md.txt).

### Customize polyline formats

> [!NOTE]
> **Note:** Remaining route reporting triggers the [Navigation Connect Enterprise SKU](https://developers.google.com/maps/documentation/navigation/connect/usage-and-billing.md.txt#pricing-for-product).

If you've enabled [remaining route reporting](https://developers.google.com/maps/documentation/navigation/connect/create-trip.md.txt#optional-configurations)
during trip creation, you can customize the representation of the returned
remaining route polyline when calling the `GetTrip` method.

To choose a format for the polyline, include the `routePolylineFormat`
parameter in your request. Supported formats include the following:

- **`ENCODED`**: A standard encoded polyline string (5 decimal points).
- **`S2ENCODED`**: An encoded S2Polyline.
- **`GEO_JSON`**: A GeoJSON LineString format.

> [!NOTE]
> **Note:** You can't customize the polyline format for Google Cloud Pub/Sub updates. Unlike the `GetTrip` method, Pub/Sub messages always use a unified GeoJSON `FeatureCollection` to combine polyline geometry with traffic speeds automatically.

## Option 2: Use Google Cloud Pub/Sub

To receive regular trip updates, subscribe to a Google Cloud Pub/Sub topic.
After the driver consents, Navigation Connect sends updates directly to your
topic.

> [!NOTE]
> **Note:** Google Cloud Pub/Sub charges are separate from Navigation Connect API charges. For more information, see [Pub/Sub pricing](https://cloud.google.com/pubsub/pricing).

For an introduction to messaging, see the
[Pub/Sub Quickstart](https://cloud.google.com/pubsub/docs/publish-receive-messages-console).

The following sections describe how to use Google Cloud Pub/Sub to receive data
from a navigation session with Google Maps or Waze.

### 1. Create a topic

Create a topic named exactly `navigation_connect_trip_notifications` in your
Google Cloud project, as follows:

1. Enable the [Pub/Sub API](https://console.cloud.google.com/apis/library/pubsub.googleapis.com).
2. Go to the [Pub/Sub topics page](https://console.cloud.google.com/cloudpubsub/topicList) in the Google Cloud console.
3. Click **Create Topic**.
4. Enter `navigation_connect_trip_notifications` in the **Topic ID** field.

   > [!NOTE]
   > **Note:** The topic ID must match for the Navigation Connect integration to work.

5. Click **Create**.

The console displays the full topic name as `projects/project-number/topics/navigation_connect_trip_notifications`, where `project-number` is your unique project number.

### 2. Grant publish permission to the Navigation Connect service account

Google uses a service account to publish trip updates to Google Cloud Pub/Sub
topics. To receive updates in your topic, grant `projects.topics.publish`
permission for this topic to the following service account:
`geo-navigation-connect-pubsub@system.gserviceaccount.com`.

For more information, see the [Pub/Sub documentation on access
control](https://cloud.google.com/pubsub/docs/access-control).

> [!NOTE]
> **Note:** You should only grant the **Pub/Sub Publisher** role to the Google Navigation Connect service account for your specific Navigation Connect topic.

### 3. Integrate with your backend

To process updates, write a server-side application that authenticates and
subscribes to your topic. Use the
[Pub/Sub Client Libraries](https://cloud.google.com/pubsub/docs/publish-receive-messages-client-library)
for streamlined development. For testing, you can also use the
[GCloud CLI](https://cloud.google.com/pubsub/docs/publish-receive-messages-gcloud)
and the
[Google Console](https://cloud.google.com/pubsub/docs/publish-receive-messages-console).

### 4. Test your subscription

Verify your setup using the gcloud CLI or Google Cloud console.

### gcloud CLI

Pull messages from a subscription (for example, `my-sub`) using the following
command:

```bash
gcloud pubsub subscriptions pull my-sub --auto-ack
```

### Google Cloud console

In the Google Cloud console, perform the following steps:

1. Open the **Subscriptions** page.
2. Select your subscription and click the **Messages** tab.
3. Click **Pull**.

## What's next

Once you start receiving trip data, parse the data to use it in your systems and
apps.

[Handle trip data](https://developers.google.com/maps/documentation/navigation/connect/handle-trip-data.md.txt)