Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Google Navigation for Flutter plugin (Beta)

License

NotificationsYou must be signed in to change notification settings

googlemaps/flutter-navigation-sdk

European Economic Area (EEA) developers

If your billing address is in the European Economic Area, effective on 8 July 2025, theGoogle 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 provides aGoogle Navigation widget to Flutter apps targeting Android and iOS.

Note

This package is in Beta until it reaches version 1.0. According tosemantic versioning, breaking changes may be introduced before 1.0.

Requirements

AndroidiOS
Minimum mobile OS supportedAPI level 23+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.

Installation

To add the Google Navigation for Flutter package to your project, use the command:

flutter pub add google_navigation_flutter

Android

Set theminSdk inandroid/app/build.gradle:

android {    defaultConfig {        minSdk23    }}

IfminSdk is set to less than 34 (API 34), you need to configure desugaring for your Android app.To enable desugaring, add the following configurations toandroid/app/build.gradle file:

android {...    compileOptions {        coreLibraryDesugaringEnabledtrue...    }}dependencies {    coreLibraryDesugaring'com.android.tools:desugar_jdk_libs_nio:2.0.4'}

iOS

  1. Open the ios/Podfile config file in your preferred IDE.
  2. Add the following lines to the beginning of this Podfile:
  # Set platform to 16.0 to enable latest Google Maps SDK  platform :ios, '16.0'
  1. In Xcode open Info.plist file and addApp registers for location updates to the list ofRequired background modes

Set Google Maps API Key

Add your API key to the Flutter project usingthese instructions for the corresponding Android (build.gradle) and iOS (AppDelegate.swift) files. The instructions for this step in the google_maps_flutter package documentation apply to the google_navigation_flutter package as well.

See the example configuration for Secrets Gradle Plugin in the example app'sbuild.gradle file.To securely load your API key, use theSecrets Gradle Plugin. This plugin helps manage API keys without exposing them in your app's source code.

For more details, seeGoogle Navigation SDK Documentation.

Usage

You can now add aGoogleMapsNavigationView widget to your widget tree.

The view can be controlled with theGoogleNavigationViewController that is passed to viaonViewCreated callback.

TheGoogleMapsNavigationView widget should be used within a widget with a bounded size. Using itin an unbounded widget will cause the application to throw a Flutter exception.

You can also add a bare GoogleMapsMapView that works as a normal map view without navigation functionality.

Add a navigation view

import'package:flutter/material.dart';import'package:google_navigation_flutter/google_navigation_flutter.dart';classNavigationSampleextendsStatefulWidget {constNavigationSample({super.key});@overrideState<NavigationSample>createState()=>_NavigationSampleState();}class_NavigationSampleStateextendsState<NavigationSample> {GoogleNavigationViewController? _navigationViewController;bool _navigationSessionInitialized=false;@overridevoidinitState() {super.initState();_initializeNavigationSession();  }Future<void>_initializeNavigationSession()async {if (!awaitGoogleMapsNavigator.areTermsAccepted()) {awaitGoogleMapsNavigator.showTermsAndConditionsDialog('Example title','Example company',      );    }// Note: make sure user has also granted location permissions before starting navigation session.awaitGoogleMapsNavigator.initializeNavigationSession(taskRemovedBehavior:TaskRemovedBehavior.continueService);setState(() {      _navigationSessionInitialized=true;    });  }@overrideWidgetbuild(BuildContext context) {returnScaffold(      appBar:AppBar(title:constText('Google Maps Navigation Sample')),      body: _navigationSessionInitialized?GoogleMapsNavigationView(              onViewCreated: _onViewCreated,              initialNavigationUIEnabledPreference:NavigationUIEnabledPreference.disabled,// Other view initialization settings            ):constCenter(child:CircularProgressIndicator()),    );  }void_onViewCreated(GoogleNavigationViewController controller) {    _navigationViewController= controller;    controller.setMyLocationEnabled(true);// Additional setup can be added here.  }@overridevoiddispose() {if (_navigationSessionInitialized) {GoogleMapsNavigator.cleanup();    }super.dispose();  }}

Note

Route calculation is only available after the Navigation SDK has successfully acquired the user's location. If the location is not yet available when trying to set a destination, the SDK will return a NavigationRouteStatus.locationUnavailable status.

To avoid this, ensure that the SDK has provided a valid user location before calling the setDestinations function. You can do this by subscribing to the RoadSnappedLocationUpdatedEvent and waiting for the first valid location update.

Task Removed Behavior

ThetaskRemovedBehavior parameter of navigation session initialization defines how the navigation should behave when a task is removed from the recent apps list on Android. It can either:

  • TaskRemovedBehavior.continueService: Continue running in the background. (default)
  • TaskRemovedBehavior.quitService: Shut down immediately.

This parameter has only an effect on Android.

Add a map view

@overrideWidgetbuild(BuildContext context) {returnScaffold(      appBar:AppBar(title:constText('Google Maps Navigation Sample')),      body: _navigationSessionInitialized?GoogleMapsMapView(              onViewCreated: _onViewCreated,              initialCameraPosition:CameraPosition(// Initialize map to user location.                target: _userLocation!,                zoom:15,              ),// Other view initialization settings            ):constCenter(child:CircularProgressIndicator()),    );  }

See theexample directory for a complete navigation sample app.

Requesting and handling permissions

The Google Navigation SDK Flutter plugin 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 themain.dart file of the example application:

PermissionStatus _locationPermissionStatus=PermissionStatus.denied;// .../// Request permission for accessing the device's location.////// Android: Fine and Coarse Location/// iOS: CoreLocation (Always and WhenInUse)Future<void>_requestLocationPermission()async {finalPermissionStatus status=awaitPermission.location.request();setState(() {    _locationPermissionStatus= status;  });}// ...@overrideWidgetbuild(BuildContext context) {_requestLocationPermission();  ...}

Support for Android Auto and Apple CarPlay

This plugin is compatible with both Android Auto and Apple CarPlay infotainment systems. For more details, please refer to the respective platform documentation:

Known issues

Compatibility with other libraries

This package uses the Google MapsNavigation SDK for Android and iOS, which includes a dependency on theGoogle Maps SDK. If your project includes other flutter libraries withGoogle Maps SDK dependencies, you may encounter build errors due to version conflicts. To avoid this, it's recommended to avoid using multiple packages with Google Maps dependencies.

Note

This package provides aGoogleMapsMapView widget, which can be used as a classic Google Maps view without navigation. SeeAdd a map view for details.

Contributing

See theContributing guide.

Terms of Service

This library uses Google Maps Platform services. Use of Google Maps Platform services through this library is subject to theGoogle 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 SupportTechnical Support Services Guidelines, theSLA, or theDeprecation Policy (however, any Google Maps Platform services used by the library remain subject to the Google Maps Platform Terms of Service).

This package adheres tosemantic 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, pleasefile an issue on GitHub. If you would like to get answers to technical questions from other Google Maps Platform developers, ask through one of ourdeveloper community channels. If you'd like to contribute, please check theContributing guide.


[8]ページ先頭

©2009-2025 Movatter.jp