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
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 instead.
- You need a trip-following consumer experience inside a native iOS app. Use Consumer SDK for iOS instead.
- You need to report driver location and trip progress from the driver's Android app to Fleet Engine. Use Driver SDK for Android instead.
- You need to report driver location and trip progress from the driver's iOS app to Fleet Engine. Use Driver SDK for iOS instead.
- You need a general web map that doesn't follow Fleet Engine trips or tasks. Use Maps JavaScript API instead.
JavaScript Consumer SDK: setup
- Authentication: API key, JSON Web Token (JWT)
- Also enable: Maps JavaScript API, Fleet Engine Service
- Usage attribution: Optional (beta) Mobility Transaction ID: set
google.maps.Settings.getInstance().experienceIdsto an array of Mobility Transaction IDs (or related IDs) before you create aJourneySharingMapView.experienceIdsis available only in thev=betachannel of the Maps JavaScript API. - Get started: Set up JavaScript Consumer SDK
- Reference: JavaScript Consumer SDK reference
- Release notes: JavaScript Consumer SDK release notes
JavaScript Consumer SDK: related products
- Often used with: Fleet Engine Service, Maps JavaScript API, Driver SDK for Android, Driver SDK for iOS
JavaScript Consumer SDK: common mistakes
- Problem: If you don't give the
JourneySharingMapViewmap an initial viewport (center and zoom), the map's'ready'event might not fire. Fix: CallmapView.map.setCenter(...)andmapView.map.setZoom(...)after you create the map view. See /maps/documentation/mobility/journey-sharing/on-demand/javascript/share-journey. - 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: AddlocationProvider.addListener('error', ...)and wrap library calls intry...catchblocks. See /maps/documentation/mobility/journey-sharing/on-demand/javascript/share-journey. - Problem: The
google.maps.journeySharingclasses aren't available unless you load thejourneySharinglibrary. Fix: Addlibraries=journeySharingto the Maps JavaScript API script URL, or load the classes withawait google.maps.importLibrary("journeySharing"). See /maps/documentation/mobility/journey-sharing/on-demand/javascript/share-journey. - 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
authTokenFetcherthat returns the token andexpiresInSeconds. See /maps/documentation/mobility/journey-sharing/on-demand/javascript/setup.
JavaScript Consumer SDK: legacy and deprecated features
JourneySharingMapViewandJourneySharingMapViewOptionsmarker and polyline setup options (vehicleMarkerSetup,originMarkerSetup,destinationMarkerSetup,waypointMarkerSetup,anticipatedRoutePolylineSetup,takenRoutePolylineSetup, and others): Deprecated. Replacement:MarkerCustomizationFunctionandPolylineCustomizationFunctionoptions on the location provider (for example,vehicleMarkerCustomization). Symptom: Scheduled for removal in a future release. See the migration guide.JourneySharingMapView.locationProviderandJourneySharingMapViewOptions.locationProvider: Deprecated. Replacement:JourneySharingMapView.locationProvidersandJourneySharingMapViewOptions.locationProviders.JourneySharingMapViewmarker and polyline list properties (vehicleMarkers,originMarkers,destinationMarkers,waypointMarkers,anticipatedRoutePolylines,takenRoutePolylines, and task marker properties): Deprecated. Replacement:MarkerCustomizationFunctionandPolylineCustomizationFunctioncallbacks on the location provider. See the migration guide.
What you can do with JavaScript Consumer SDK
See the guides linked below for each task, or compare across products in the Capabilities Explorer.
- Add a route polyline that tracks a trip from Fleet Engine to a map on a web page or mobile app.
- Update trip progress along a route in a map on a web page or mobile app for a Fleet Engine trip.
- Change the style of roads, polylines, and polygons on a map that tracks the progress of a trip from Fleet Engine.
- Display or hide map features on a map that tracks the progress of a trip from Fleet Engine.
- Change the style of icons and text labels on a map that tracks the progress of a trip from Fleet Engine.
- Apply different map styles to different zoom levels on a map that tracks the progress of a trip from Fleet Engine.
- Change the density of places on a map that tracks the progress of a trip from Fleet Engine. 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. 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. 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.
- Customize the route polyline on a map that tracks the progress of a trip from Fleet Engine.