Retrieve trip data

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.

#!/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"

Customize polyline formats (Waze only)

If you've enabled remaining route reporting during trip creation, you can customize the representation of the returned active 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.

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.

For an introduction to messaging, see the Pub/Sub Quickstart.

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.
  2. Go to the Pub/Sub topics page in the Google Cloud console.
  3. Click Create Topic.
  4. Enter navigation_connect_trip_notifications in the Topic ID field.

  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.

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 for streamlined development. For testing, you can also use the GCloud CLI and the Google 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:

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