Skip to content

googlemaps/react-native-driver-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

React Native: DriverSDK Library

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.

Description

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.

Requirements

Android iOS
Minimum mobile OS supported SDK 24+ iOS 16.0+

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.

React Native Compatibility

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.

Installation

  1. 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.

  2. 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}
  3. Install the @googlemaps/react-native-navigation-sdk dependency:

    npm install --save @googlemaps/react-native-navigation-sdk

    or

    yarn add @googlemaps/react-native-navigation-sdk

Android

Disable new architecture

This package does not yet support new architecture. Make sure new architecture is disabled in your android/gradle.properties file:

newArchEnabled=false

Enable Jetifier

To ensure compatibility with AndroidX, enable Jetifier in your android/gradle.properties file:

# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true

Enable Core Library Desugaring

Core 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'
}

Minimum SDK Requirements for Android

The minSdkVersion for your Android project must be set to 24 or higher in android/app/build.gradle:

android {
    defaultConfig {
        minSdkVersion 24
    }
}

Set Google Maps API Key

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.

iOS

Disable new architecture

This package does not yet support new architecture. Make sure new architecture is disabled in your ios/Podfile:

ENV['RCT_NEW_ARCH_ENABLED'] = '0'

Set Google Maps API Key

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];
}

Usage

Ridesharing

Initializing the API

  1. As mentioned above, this library depends on the React Native: NavigationSDK library. Specifically, it depends on the existence of a NavigationView component in the application.

  2. 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();
  3. 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();
  4. 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.

Getting a RidesharingVehicleReporter

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);

Delivery

Initializing the API

  1. As mentioned above, this library depends on the React Native: NavigationSDK library. Specifically, it depends on the existence of a NavigationView component in the application. Please refer to the Navigation SDK Sample app for all details on how to set up the navigation component.

  2. 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();
  3. 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.

Getting a DeliveryVehicleReporter

The vehicle reporter allows developers to enable/disable location reporting to Fleet Engine.

  const vehicleReporter = deliveryApi.getDeliveryVehicleReporter()
  await vehicleReporter.setLocationTrackingEnabled(true);

Getting a DeliveryVehicleManager

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();

Other APIs

Set update interval status (seconds) - RideSharingAPI & DeliveryDriverAPI:

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);

Get the Driver SDK version: - RideSharingAPI & DeliveryDriverAPI:

To get the DriverSDK version being used, you can call the getDriverSdkVersion method. See the sample code below:

  const sdkVersion = await driverApi.getDriverSdkVersion();

List of functions in ODRD

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.

List of functions in LMFS

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.

Requesting and handling permissions

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,
        });
    }
};

Contributing

See the Contributing guide.

Terms of Service

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.

Support

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.

About

No description, website, or topics provided.

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •