European Economic Area (EEA) developers
If your billing address is in the European Economic Area, effective on 8 July 2025, the Google Maps Platform EEA Terms of Service will apply to your use of the Services. Functionality varies by region. Learn more.
This is the beta release of the Google Driver SDK package for React Native. It is an early look at the package and is intended for testing and feedback collection. The functionalities and APIs in this version are subject to change.
Note
This package is in Beta until it reaches version 1.0. According to semantic versioning, breaking changes may be introduced before 1.0.
| Android | iOS | |
|---|---|---|
| Minimum mobile OS supported | SDK 24+ | iOS 16.0+ |
- A React Native project
- A Google Cloud project
- If you are a Mobility Services developer, you must contact Sales as described in Mobility services documentation.
- If you are not a Mobility Services developer, refer to Setup Google Cloud Project for instructions.
- An API key from the project above
- The API key must be configured for both Android and iOS. Refer to Android Using Api Keys and iOS Using Api Keys respectively for instructions.
- If targeting Android, Google Play Services installed and enabled
- Attributions and licensing text added to your app
Important
Apply API restrictions to the API key to limit usage to "Navigation SDK, "Maps SDK for Android", and "Maps SDK for iOS" for enhanced security and cost management. This helps guard against unauthorized use of your API key.
Important
This package does not yet support React Native's new architecture. Make sure the new architecture is disabled in your project configuration as shown in the Installation section.
-
This repository is currently private. In order to install the library, you must authenticate with SSH first. See Connecting to GitHub with SSH for instructions on how to provide SSH keys.
-
To install the library run the following command from your project root:
npm install --save https://github.com/googlemaps/react-native-driver-sdk#{version_tag}or
yarn add @googlemaps/react-native-driver-sdk@https://github.com/googlemaps/react-native-driver-sdk#{version_tag} -
Install the
@googlemaps/react-native-navigation-sdkdependency:npm install --save @googlemaps/react-native-navigation-sdk
or
yarn add @googlemaps/react-native-navigation-sdk
This package does not yet support new architecture. Make sure new architecture is disabled in your android/gradle.properties file:
newArchEnabled=falseTo ensure compatibility with AndroidX, enable Jetifier in your android/gradle.properties file:
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=trueCore library desugaring must be enabled for your Android project, regardless of your minSdkVersion.
To enable desugaring, update your android/app/build.gradle file:
android {
...
compileOptions {
coreLibraryDesugaringEnabled true
...
}
}
dependencies {
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs_nio:2.0.4'
}The minSdkVersion for your Android project must be set to 24 or higher in android/app/build.gradle:
android {
defaultConfig {
minSdkVersion 24
}
}To securely store your API key, it is recommended to use the Google Maps Secrets Gradle Plugin. This plugin helps manage API keys without exposing them in your app's source code.
See example configuration for secrets plugin at example applications build.gradle file.
This package does not yet support new architecture. Make sure new architecture is disabled in your ios/Podfile:
ENV['RCT_NEW_ARCH_ENABLED'] = '0'To set up, specify your API key in the application delegate ios/Runner/AppDelegate.m:
#import <GoogleMaps/GoogleMaps.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[GMSServices provideAPIKey:@"API_KEY"];
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
-
As mentioned above, this library depends on the React Native: NavigationSDK library. Specifically, it depends on the existence of a
NavigationViewcomponent in the application. -
In your react-native component, import and instantiate the RidesharingDriverapi and reference it through variable.
import RidesharingDriverApi from "@googlemaps/react-native-driver-sdk"; const ridesharing = new RidesharingDriverapi();
-
Start navigation. Please refer to the Navigation SDK Sample app for all details on how to set up the navigation component and its listeners.
const { navigationController } = useNavigation(); ... await navigationController.init();
-
Second step is to initialize the Api. Navigation must be initialized before the Driver SDK is initialized.
await ridesharingDriverApi .initialize( PROVIDER_ID, VEHICLE_ID, (tokenContext) => { // Check if the token is expired, in such case request a new one. return Promise.resolve(authToken || ""); }, (statusLevel, statusCode, message) => { console.log("onStatusUpdate: " + statusLevel + " " + statusCode + " " + message); } );
Note: The initialize method takes a onGetTokenCallback field as parameter. This will be called periodically to ensure the token stays refresh while there's requests to Fleet Engine. Please make sure to check that the token is valid (e.g. checking expiration time) before setting it.
The vehicle reporter allows developers to enable/disable location reporting to Fleet Engine, as well as to report changes in the vehicle state (E.g. Online or Offline).
const vehicleReporter = ridesharingDriverApi.getRidesharingVehicleReporter()
await vehicleReporter.setLocationTrackingEnabled(true);
await vehicleReporter.setVehicleState(VehicleState.ONLINE);-
As mentioned above, this library depends on the React Native: NavigationSDK library. Specifically, it depends on the existence of a
NavigationViewcomponent in the application. Please refer to the Navigation SDK Sample app for all details on how to set up the navigation component. -
In your react-native component, import and instantiate the RidesharingDriverapi and reference it through variable.
import DeliveryDriverApi from "@googlemaps/react-native-driver-sdk"; const deliveryApi = new DeliveryDriverapi();
-
Second step is to initialize the Api.
await deliveryApi .initialize( PROVIDER_ID, DELIVERY_VEHICLE_ID, (tokenContext) => { // Check if the token is expired, in such case request a new one. return Promise.resolve(authToken || ""); }, (statusLevel, statusCode, message) => { console.log("onStatusUpdate: " + statusLevel + " " + statusCode + " " + message); } );
Note: The initialize method takes a onGetTokenCallback field as parameter. This will be called periodically to ensure the token stays refresh while there's requests to Fleet Engine. Please make sure to check that the token is valid (e.g. checking expiration time) before setting it.
The vehicle reporter allows developers to enable/disable location reporting to Fleet Engine.
const vehicleReporter = deliveryApi.getDeliveryVehicleReporter()
await vehicleReporter.setLocationTrackingEnabled(true);The vehicle managers allows developers to fetch the DeliveryVehicle linked to the Driver Api from Fleet Engine.
const vehicleManager = deliveryApi.getDeliveryVehicleManager()
const deliveryVehicle = await vehicleManager.getDeliveryVehicle();To set the time interval of your vehicle updates, you can use the setLocationReportingInterval method of the Driver Api's. Pass the value in seconds of your preferred interval. See the sample code below where location will be updated every 20 seconds:
await driverApi.setLocationReportingInterval(20);To get the DriverSDK version being used, you can call the getDriverSdkVersion method. See the sample code below:
const sdkVersion = await driverApi.getDriverSdkVersion();| Function | Description |
|---|---|
RidesharingDriverApi.initialize |
Create the instance of RidesharingAPI. |
RidesharingDriverApi.getRidesharingVehicleReporter |
Vehicle reporter for the vehicle that reports location and vehicle state to Fleet Engine. An app is allowed only one vehicle reporter. |
RidesharingVehicleReporter.setLocationTrackingEnabled(boolean) |
Enable/disabled location tracking(logs). |
RidesharingVehicleReporter.setVehicleState(VehicleState) |
Set vehicle state to Online/Offline to Fleet Engine. |
RidesharingVehicleReporter.setLocationReportingInterval(number) |
Set the reporting interval(seconds). |
RidesharingDriverApi.getDriverSdkVersion() |
Get native driversdk version. |
RidesharingDriverApi.clearInstance() |
Clear the api instance. |
RidesharingDriverApi.setAbnormalTerminationReporting(boolean) |
Enable/disable abnormal termination reporting. |
| Function | Description |
|---|---|
DeliveryDriverApi.initialize |
Create the instance of DeliveryDriverAPI. |
DeliveryDriverApi.getDeliveryVehicleReporter |
Vehicle reporter for a delivery vehicle that reports location and stop information. An app is allowed only one vehicle reporter. |
DeliveryDriverApi.getDeliveryVehicleManager |
Returns a vehicle manager that can be used to fetch the delivery vehicle from Fleet Engine |
DeliveryVehicleReporter.setLocationTrackingEnabled(boolean) |
Enable/disabled location tracking(logs). |
DeliveryVehicleReporter.setLocationReportingInterval(number) |
Set the log interval(seconds). |
DeliveryVehicleReporter.getDriverSdkVersion() |
Get delivery driversdk version. |
DeliveryVehicleManager.getDeliveryVehicle() |
Fetch the delivery vehicle from Fleet Engine |
DeliveryVehicleReporter.clearInstance() |
Clear instance. |
DeliveryVehicleReporter.setAbnormalTerminationReporting(boolean) |
Enable/disable abnormal termination reporting. |
The Google Navigation SDK React Native library offers functionalities that necessitate specific permissions from the mobile operating system. These include, but are not limited to, location services, background execution, and receiving background location updates.
Note
The management of these permissions falls outside the scope of the Navigation SDKs for Android and iOS. As a developer integrating these SDKs into your applications, you are responsible for requesting and obtaining the necessary permissions from the users of your app.
You can see example of handling permissions in the app.tsx file of the sample application:
import {request, PERMISSIONS, RESULTS} from 'react-native-permissions';
// ...
// Request permission for accessing the device's location.
const requestPermissions = async () => {
const result = await request(
Platform.OS =="android" ?
PERMISSIONS.ANDROID.ACCESS_COARSE_LOCATION :
PERMISSIONS.IOS.LOCATION_ALWAYS,
);
if (result == RESULTS.GRANTED) {
setArePermissionsApproved(true);
} else {
Snackbar.show({
text: 'Permissions are needed to proceed with the app. Please re-open and accept.',
duration: Snackbar.LENGTH_SHORT,
});
}
};See the Contributing guide.
This library uses Google Maps Platform services. Use of Google Maps Platform services through this library is subject to the Google Maps Platform Terms of Service.
This library is not a Google Maps Platform Core Service. Therefore, the Google Maps Platform Terms of Service (e.g. Technical Support Services, Service Level Agreements, and Deprecation Policy) do not apply to the code in this library.
This package is offered via an open source license. It is not governed by the Google Maps Platform Support Technical Support Services Guidelines, the SLA, or the Deprecation Policy (however, any Google Maps Platform services used by the library remain subject to the Google Maps Platform Terms of Service).
This package adheres to semantic versioning to indicate when backwards-incompatible changes are introduced. Accordingly, while the library is in version 0.x, backwards-incompatible changes may be introduced at any time.
If you find a bug, or have a feature request, please file an issue on GitHub. If you would like to get answers to technical questions from other Google Maps Platform developers, ask through one of our developer community channels. If you'd like to contribute, please check the Contributing guide.