🌐 AI搜索 & 代理 主页
Skip to content

googlemaps/flutter-driver-sdk

Google Maps Driver (Preview)

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 repository contains a Flutter plugin that allows users to use the Google Maps Driver SDK for Android and iOS. The plugin has a dependency on the google-maps-navigation plugin.

Requirements

Android iOS
Support SDK 23+ iOS 16.0+

Important

Project ID need to be allowlisted before using this plugin. Please contact your Google representative to get your Project ID allowlisted.

Installation

  1. This repository is currently private. You will need to add the package dependency using Git with SSH in the app's pubspec.yaml file. See Connecting to GitHub with SSH for instructions on how to provide SSH keys.
  dependencies:
    google_driver_flutter:
      git:
        url: git@github.com:googlemaps/flutter-driver-sdk.git
  1. Follow the instructions at the google_navigation_flutter plugin Readme to add your API key to the appropriate files in your Flutter project.

    Google Maps Navigation Installation

Usage

Before initializing the delivery or the ridesharing driver, you must initialize the navigation session.

Delivery Driver (LMFS)

import 'package:flutter/material.dart';
import 'package:google_driver_flutter/google_driver_flutter.dart';
import 'package:google_navigation_flutter/google_navigation_flutter.dart';

class DeliveryDriverSample extends StatefulWidget {
  const DeliveryDriverSample({super.key});

  @override
  State<DeliveryDriverSample> createState() => _DeliveryDriverSampleState();
}

class _DeliveryDriverSampleState extends State<DeliveryDriverSample> {
  String _providerId = "Your Google Maps Platform Provider ID";
  String _vehicleId = "Delivery Vehicle ID"; // Get vehicle ID from your backend

  @override
  void initState() {
    super.initState();
    _initialize();
  }

  Future<void> _initialize() async {
    if (!await GoogleMapsNavigator.areTermsAccepted()) {
      await GoogleMapsNavigationManager.showTermsAndConditionsDialog(
        'Example title',
        'Example company',
      );
    }
    // Note: make sure user has also granted location permissions before starting navigation session.
    await GoogleMapsNavigator.initializeNavigationSession();

    // Initialize delivery driver.
    await DeliveryDriver.initialize(
        providerId: _providerId,
        vehicleId: _vehicleId,
        onGetToken: (AuthTokenContext context) async {
            final String token = "token" // Get token from your backend
            return token;
        });

    // Enable location tracking.
    await DeliveryDriver.vehicleReporter
            .setLocationTrackingEnabled(true);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Google Maps Delivery Driver Sample')),
      body: GoogleMapsNavigationView(
              onViewCreated: _onViewCreated,
            ),
    );
  }

  ...

  @override
  void dispose() {
    ...
    DeliveryDriver.dispose();
    GoogleMapsNavigator.cleanup();
    ...
    super.dispose();
  }
}

See the example directory for a complete delivery driver sample app.

Ridesharing Driver (ODRD)

import 'package:flutter/material.dart';
import 'package:google_driver_flutter/google_driver_flutter.dart';
import 'package:google_navigation_flutter/google_navigation_flutter.dart';

class RidesharingDriverSample extends StatefulWidget {
  const RidesharingDriverSample({super.key});

  @override
  State<RidesharingDriverSample> createState() => _RidesharingDriverSampleState();
}

class _RidesharingDriverSampleState extends State<RidesharingDriverSample> {
  String _providerId = "Your Google Maps Platform Provider ID";
  String _vehicleId = "Ridesharing Vehicle ID"; // Get vehicle ID from your backend

  @override
  void initState() {
    super.initState();
    _initialize();
  }

  Future<void> _initialize() async {
    if (!await GoogleMapsNavigator.areTermsAccepted()) {
      await GoogleMapsNavigationManager.showTermsAndConditionsDialog(
        'Example title',
        'Example company',
      );
    }
    // Note: make sure user has also granted location permissions before starting navigation session.
    await GoogleMapsNavigator.initializeNavigationSession();

    // Initialize ridesharing driver.
    await RidesharingDriver.initialize(
        providerId: _providerId,
        vehicleId: _vehicleId,
        onGetToken: (AuthTokenContext context) async {
            final String token = "token" // Get token from your backend
            return token;
        });

    // Enable location tracking.
    await RidesharingDriver.vehicleReporter
            .setLocationTrackingEnabled(true);

    // After location tracking is enabled, the vehicle state can be set to online.
    await RidesharingDriver.vehicleReporter
            .setVehicleState(RidesharingVehicleState.online);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Google Maps Ridesharing Driver Sample')),
      body: GoogleMapsNavigationView(
              onViewCreated: _onViewCreated,
            ),
    );
  }

  ...

  @override
  void dispose() {
    ...
    RidesharingDriver.dispose();
    GoogleMapsNavigator.cleanup();
    ...
    super.dispose();
  }
}

See the example directory for a complete ridesharing driver sample app.

Contributing

See the Contributing guide.

Terms of Service

This package uses Google Maps Platform services, and any use of Google Maps Platform is subject to the Terms of Service.

For clarity, this package, and each underlying component, is not a Google Maps Platform Core Service.

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 5