- Notifications
You must be signed in to change notification settings - Fork39
Google Navigation for Flutter plugin (Beta)
License
googlemaps/flutter-navigation-sdk
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
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.
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.
| Android | iOS | |
|---|---|---|
| Minimum mobile OS supported | API level 23+ | iOS 16.0+ |
- A Flutter project
- A Google Cloud project
- If you are a Mobility Services developer, you must contact Sales as described inMobility services documentation.
- If you are not a Mobility Services developer, refer toSetup Google Cloud Project for instructions.
- AnAPI key from the project above
- The API key must be configured for both Android and iOS. Refer toAndroid Using Api Keys andiOS Using Api Keys respectively for instructions.
- If targeting Android,Google Play Services installed and enabled and minimum Kotlin version 2.0
- 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.
To add the Google Navigation for Flutter package to your project, use the command:
flutter pub add google_navigation_flutterSet 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'}- Open the ios/Podfile config file in your preferred IDE.
- 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'- In Xcode open Info.plist file and add
App registers for location updatesto the list ofRequired background modes
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.
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.
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.
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.
@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.
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(); ...}
This plugin is compatible with both Android Auto and Apple CarPlay infotainment systems. For more details, please refer to the respective platform documentation:
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.
See theContributing guide.
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.
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.
About
Google Navigation for Flutter plugin (Beta)
Topics
Resources
License
Contributing
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors13
Uh oh!
There was an error while loading.Please reload this page.