The JavaScript Consumer SDK lets a web-based consumer app show the location of vehicles and other locations of interest tracked in Fleet Engine on a map, so consumers can follow the progress of an on-demand trip or a scheduled shipment. It loads as the `journeySharing` library of the Maps JavaScript API.

## JavaScript Consumer SDK: key facts

- **Product:** JavaScript Consumer SDK
- **Also known as:** Consumer SDK for JavaScript, Mobility services on-demand trips JavaScript, JavaScript SDK
- **Category:** Routes
- **Platform:** JavaScript (browser)
- **Runs on:** Client (app or browser code)
- **Launch stage:** GA
- **Lifecycle:** Active
- **Overview:** [JavaScript Consumer SDK overview](https://developers.google.com/maps/documentation/mobility/journey-sharing)

## JavaScript Consumer SDK: when to use it

**Use JavaScript Consumer SDK when:**

- You need to show consumers a vehicle's live location and route for an on-demand trip that Fleet Engine tracks, in a web page or web app.
- You need to let consumers follow the pickup or delivery progress of a scheduled shipment tracked in Fleet Engine in a browser.
- You need to show ETA, remaining distance, and live traffic on the route for a trip in a web-based map view.
- You need to customize trip markers, route polylines, or map styling in a web consumer tracking view.
**Don't use JavaScript Consumer SDK when:**

- You need a trip-following consumer experience inside a native Android app. Use [Consumer SDK for Android](https://developers.google.com/maps/documentation/mobility/journey-sharing/quick-reference-android.md.txt) instead.
- You need a trip-following consumer experience inside a native iOS app. Use [Consumer SDK for iOS](https://developers.google.com/maps/documentation/mobility/journey-sharing/quick-reference-ios.md.txt) instead.
- You need to report driver location and trip progress from the driver's Android app to Fleet Engine. Use [Driver SDK for Android](https://developers.google.com/maps/documentation/mobility/driver-sdk/quick-reference-android.md.txt) instead.
- You need to report driver location and trip progress from the driver's iOS app to Fleet Engine. Use [Driver SDK for iOS](https://developers.google.com/maps/documentation/mobility/driver-sdk/quick-reference-ios.md.txt) instead.
- You need a general web map that doesn't follow Fleet Engine trips or tasks. Use [Maps JavaScript API](https://developers.google.com/maps/documentation/javascript/quick-reference.md.txt) instead.

## JavaScript Consumer SDK: setup

- **Authentication:** API key, JSON Web Token (JWT)
- **Also enable:** [Maps JavaScript API](https://developers.google.com/maps/documentation/javascript/quick-reference.md.txt), [Fleet Engine Service](https://developers.google.com/maps/documentation/mobility/fleet-engine/quick-reference.md.txt)
- **Usage attribution:** Optional (beta) Mobility Transaction ID: set `google.maps.Settings.getInstance().experienceIds` to an array of Mobility Transaction IDs (or related IDs) before you create a `JourneySharingMapView`. `experienceIds` is available only in the `v=beta` channel of the Maps JavaScript API.
- **Get started:** [Set up JavaScript Consumer SDK](https://developers.google.com/maps/documentation/mobility/journey-sharing/on-demand/javascript/setup.md.txt)
- **Reference:** [JavaScript Consumer SDK reference](https://developers.google.com/maps/documentation/javascript/reference/journey-sharing-map-view.md.txt)
- **Release notes:** [JavaScript Consumer SDK release notes](https://developers.google.com/maps/documentation/mobility/services/resources/relnotes_javascript_sdk.md.txt)

## JavaScript Consumer SDK: related products

- **Often used with:** [Fleet Engine Service](https://developers.google.com/maps/documentation/mobility/fleet-engine/quick-reference.md.txt), [Maps JavaScript API](https://developers.google.com/maps/documentation/javascript/quick-reference.md.txt), [Driver SDK for Android](https://developers.google.com/maps/documentation/mobility/driver-sdk/quick-reference-android.md.txt), [Driver SDK for iOS](https://developers.google.com/maps/documentation/mobility/driver-sdk/quick-reference-ios.md.txt)

## JavaScript Consumer SDK: common mistakes

- **Problem:** If you don't give the `JourneySharingMapView` map an initial viewport (center and zoom), the map's `'ready'` event might not fire. **Fix:** Call `mapView.map.setCenter(...)` and `mapView.map.setZoom(...)` after you create the map view. See [/maps/documentation/mobility/journey-sharing/on-demand/javascript/share-journey](https://developers.google.com/maps/documentation/mobility/journey-sharing/on-demand/javascript/share-journey.md.txt).
- **Problem:** Errors from asynchronous trip information requests don't throw. They arrive only as `'error'` events on the location provider, so they go unnoticed unless you add a listener. **Fix:** Add `locationProvider.addListener('error', ...)` and wrap library calls in `try...catch` blocks. See [/maps/documentation/mobility/journey-sharing/on-demand/javascript/share-journey](https://developers.google.com/maps/documentation/mobility/journey-sharing/on-demand/javascript/share-journey.md.txt).
- **Problem:** The `google.maps.journeySharing` classes aren't available unless you load the `journeySharing` library. **Fix:** Add `libraries=journeySharing` to the Maps JavaScript API script URL, or load the classes with `await google.maps.importLibrary("journeySharing")`. See [/maps/documentation/mobility/journey-sharing/on-demand/javascript/share-journey](https://developers.google.com/maps/documentation/mobility/journey-sharing/on-demand/javascript/share-journey.md.txt).
- **Problem:** Fleet Engine calls from the browser (a low-trust environment) need JWTs that your backend server issues. An API key alone doesn't authorize trip data access. **Fix:** Issue JWTs from your backend and provide an `authTokenFetcher` that returns the token and `expiresInSeconds`. See [/maps/documentation/mobility/journey-sharing/on-demand/javascript/setup](https://developers.google.com/maps/documentation/mobility/journey-sharing/on-demand/javascript/setup.md.txt).

## JavaScript Consumer SDK: legacy and deprecated features

- **`JourneySharingMapView` and `JourneySharingMapViewOptions` marker and polyline setup options (`vehicleMarkerSetup`, `originMarkerSetup`, `destinationMarkerSetup`, `waypointMarkerSetup`, `anticipatedRoutePolylineSetup`, `takenRoutePolylineSetup`, and others):** Deprecated. **Replacement:** `MarkerCustomizationFunction` and `PolylineCustomizationFunction` options on the location provider (for example, `vehicleMarkerCustomization`). **Symptom:** Scheduled for removal in a future release. See the [migration guide](https://developers.google.com/maps/documentation/mobility/journey-sharing/on-demand/javascript/customize-markers.md.txt).
- **`JourneySharingMapView.locationProvider` and `JourneySharingMapViewOptions.locationProvider`:** Deprecated. **Replacement:** `JourneySharingMapView.locationProviders` and `JourneySharingMapViewOptions.locationProviders`.
- **`JourneySharingMapView` marker and polyline list properties (`vehicleMarkers`, `originMarkers`, `destinationMarkers`, `waypointMarkers`, `anticipatedRoutePolylines`, `takenRoutePolylines`, and task marker properties):** Deprecated. **Replacement:** `MarkerCustomizationFunction` and `PolylineCustomizationFunction` callbacks on the location provider. See the [migration guide](https://developers.google.com/maps/documentation/mobility/journey-sharing/on-demand/javascript/customize-markers.md.txt).

## What you can do with JavaScript Consumer SDK

See the guides linked below for each task, or compare across products in the
[Capabilities Explorer](https://developers.google.com/maps/documentation/capabilities-explorer.md.txt).

- [Add a route polyline that tracks a trip from Fleet Engine to a map on a web page or mobile app.](https://developers.google.com/maps/documentation/mobility/journey-sharing/on-demand/javascript/customize-route-polylines.md.txt#style_route_polylines)
- [Update trip progress along a route in a map on a web page or mobile app for a Fleet Engine trip.](https://developers.google.com/maps/documentation/mobility/journey-sharing/on-demand/javascript/share-journey.md.txt#listen-events)
- [Change the style of roads, polylines, and polygons on a map that tracks the progress of a trip from Fleet Engine.](https://developers.google.com/maps/documentation/mobility/journey-sharing/on-demand/javascript/style.md.txt#style_the_map_with_cloud-based_maps_styling)
- [Display or hide map features on a map that tracks the progress of a trip from Fleet Engine.](https://developers.google.com/maps/documentation/mobility/journey-sharing/on-demand/javascript/style.md.txt#style_the_map_with_cloud-based_maps_styling)
- [Change the style of icons and text labels on a map that tracks the progress of a trip from Fleet Engine.](https://developers.google.com/maps/documentation/mobility/journey-sharing/on-demand/javascript/style.md.txt#style_the_map_with_cloud-based_maps_styling)
- [Apply different map styles to different zoom levels on a map that tracks the progress of a trip from Fleet Engine.](https://developers.google.com/maps/documentation/mobility/journey-sharing/on-demand/javascript/style.md.txt#style_the_map_with_cloud-based_maps_styling)
- [Change the density of places on a map that tracks the progress of a trip from Fleet Engine.](https://developers.google.com/maps/documentation/mobility/journey-sharing/on-demand/javascript/style.md.txt#style_the_map_with_cloud-based_maps_styling) Experimental **Note:** Cloud-based Maps Styling support in the Consumer SDK is GA, while POI density control is an Experimental Cloud-based Maps Styling feature (supported on light map styles only).
- [Change the style of buildings on a map that tracks the progress of a trip from Fleet Engine.](https://developers.google.com/maps/documentation/mobility/journey-sharing/on-demand/javascript/style.md.txt#style_the_map_with_cloud-based_maps_styling) Experimental **Note:** Cloud-based Maps Styling support in the Consumer SDK is GA, while 3D and footprint building style customization is an Experimental Cloud-based Maps Styling feature (supported on light map styles only).
- [Change the style of landmarks on a map that tracks the progress of a trip from Fleet Engine.](https://developers.google.com/maps/documentation/mobility/journey-sharing/on-demand/javascript/style.md.txt#style_the_map_with_cloud-based_maps_styling) Experimental **Note:** Cloud-based Maps Styling support in the Consumer SDK is GA, while landmark icon customization is an Experimental Cloud-based Maps Styling feature (supported on light map styles only).
- [Customize a marker on a map that tracks the progress of a trip from Fleet Engine.](https://developers.google.com/maps/documentation/mobility/journey-sharing/on-demand/javascript/customize-markers.md.txt)
- [Customize the route polyline on a map that tracks the progress of a trip from Fleet Engine.](https://developers.google.com/maps/documentation/mobility/journey-sharing/on-demand/javascript/customize-route-polylines.md.txt)