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

React Native library (Beta) for bringing Google Navigation SDK to Android and iOS apps using React.

License

NotificationsYou must be signed in to change notification settings

googlemaps/react-native-navigation-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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 React Native plugin that provides aGoogle Navigation component for building native Android and iOS apps using React.

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 supportedSDK 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

The current version of this package has been tested and verified to work with the following React Native versions:

0.81.1, 0.80.2, 0.79.6, 0.78.3, 0.77.3, 0.76.9, 0.75.5, 0.74.7

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 theInstallation section.

Installation

This package is listed on NPM as@googlemaps/react-native-navigation-sdk. Install it with:

npm i @googlemaps/react-native-navigation-sdk

In your TSX or JSX file, import the components you need:

import{NavigationView}from'@googlemaps/react-native-navigation-sdk';

Android

Disable new architecture

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

newArchEnabled=false

Enable Jetifier

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

#Automatically convert third-party libraries to useAndroidXandroid.enableJetifier=true

Enable Core Library Desugaring

Core library desugaringmust be enabled for your Android project, regardless of your minSdkVersion.

To enable desugaring, update yourandroid/app/build.gradle file:

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

Minimum SDK Requirements for Android

TheminSdkVersion for your Android project must be set to 24 or higher inandroid/app/build.gradle:

android {    defaultConfig {        minSdkVersion24    }}

Set Google Maps API Key

To securely store your API key, it is recommended to use theGoogle 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 applicationsbuild.gradle file.

iOS

Disable new architecture

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

ENV['RCT_NEW_ARCH_ENABLED']='0'

Set Google Maps API Key

To set up, specify your API key in the application delegateios/Runner/AppDelegate.m:

#import<GoogleMaps/GoogleMaps.h>@implementationAppDelegate- (BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions{  [GMSServicesprovideAPIKey:@"API_KEY"];return [superapplication:applicationdidFinishLaunchingWithOptions:launchOptions];}

Usage

Initializing Navigation

Wrap application with theNavigationProvider component. This will provide the necessary context for navigation throughout your app.

importReactfrom'react';import{NavigationProvider,TaskRemovedBehavior,typeTermsAndConditionsDialogOptions,}from'@googlemaps/react-native-navigation-sdk';consttermsAndConditionsDialogOptions:TermsAndConditionsDialogOptions={title:'Terms and Conditions Title',companyName:'Your Company Name',showOnlyDisclaimer:true,};constApp=()=>{return(<NavigationProvidertermsAndConditionsDialogOptions={termsAndConditionsDialogOptions}taskRemovedBehavior={TaskRemovedBehavior.CONTINUE_SERVICE}>{/* Add your application components here */}</NavigationProvider>);};exportdefaultApp;

Task Removed Behavior

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

  • CONTINUE_SERVICE: Continue running in the background. (default)
  • QUIT_SERVICE: Shut down immediately.

This prop has only an effect on Android.

Using NavigationController

You can use theuseNavigation hook to access theNavigationController and control navigation within your components. TheuseNavigation hook also provides methods to add and remove listeners.

Initializing Navigation

...const{ navigationController}=useNavigation();constinitializeNavigation=useCallback(async()=>{try{awaitnavigationController.init();console.log('Navigation initialized');}catch(error){console.error('Error initializing navigation',error);}},[navigationController]);

Note

Navigation can be controlled separately from the navigation views allowing navigation to be started and stopped independently.

Starting Navigation

To start navigation, set a destination and start guidance:

try{constwaypoint={title:'Destination',position:{lat:37.4220679,lng:-122.0859545,},};constroutingOptions={travelMode:TravelMode.DRIVING,avoidFerries:false,avoidTolls:false,};constdisplayOptions:DisplayOptions={showDestinationMarkers:true,showStopSigns:true,showTrafficLights:true,};awaitnavigationController.setDestinations([waypoint],routingOptions,displayOptions);awaitnavigationController.startGuidance();}catch(error){console.error('Error starting navigation',error);}

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 RouteStatus.LOCATION_DISABLED 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 onLocationChanged navigation callback and waiting for the first valid location update.

Adding navigation listeners

const{ navigationController, addListeners, removeListeners}=useNavigation();constonArrival=useCallback((event:ArrivalEvent)=>{if(event.isFinalDestination){console.log('Final destination reached');navigationController.stopGuidance();}else{console.log('Continuing to the next destination');navigationController.continueToNextDestination();navigationController.startGuidance();}},[navigationController]);constnavigationCallbacks=useMemo(()=>({    onArrival,// Add other callbacks here}),[onArrival]);useEffect(()=>{addListeners(navigationCallbacks);return()=>{removeListeners(navigationCallbacks);};},[navigationCallbacks,addListeners,removeListeners]);

SeeNavigationCallbacks interface for a list of available callbacks.

When removing listeners, ensure you pass the same object that was used when adding them, as multiple listeners can be registered for the same event.

Add a navigation view

You can now add aNavigationView component to your application..

The view can be controlled with theViewController (Navigation and MapView) that are retrieved from theonMapViewControllerCreated andonNavigationViewControllerCreated (respectively).

TheNavigationView compoonent should be used within a View with a bounded size. Using itin an unbounded widget will cause the application to behave unexpectedly.

// Permissions must have been granted by this point.<NavigationViewmapId="your-map-id-here"// Optional: Your map ID configured in Google Cloud ConsoleandroidStylingOptions={{primaryDayModeThemeColor:'#34eba8',headerDistanceValueTextColor:'#76b5c5',headerInstructionsFirstRowTextSize:'20f',}}iOSStylingOptions={{navigationHeaderPrimaryBackgroundColor:'#34eba8',navigationHeaderDistanceValueTextColor:'#76b5c5',}}navigationViewCallbacks={navigationViewCallbacks}mapViewCallbacks={mapViewCallbacks}onMapViewControllerCreated={setMapViewController}onNavigationViewControllerCreated={setNavigationViewController}termsAndConditionsDialogOptions={termsAndConditionsDialogOptions}/>

Add a map view

You can also add a bareMapView that works as a normal map view without navigation functionality.MapView only need aMapViewController to be controlled.

<MapViewmapId="your-map-id-here"// Optional: Your map ID configured in Google Cloud ConsolemapViewCallbacks={mapViewCallbacks}onMapViewControllerCreated={setMapViewController}/>

Control light and dark modes

Use themapColorScheme prop on bothNavigationView andMapView to force the map tiles into light, dark, or system-following mode.

For the navigation UI, pass thenavigationNightMode prop toNavigationView to configure the initial lighting mode for navigation session.

Note

When navigation UI is enabled,mapColorScheme does not affect the view styling. To control the style of the navigation UI, use thenavigationNightMode prop onNavigationView instead.

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 theApp.tsx file of the sample application:

import{request,PERMISSIONS,RESULTS}from'react-native-permissions';// ...// Request permission for accessing the device's location.constrequestPermissions=async()=>{constresult=awaitrequest(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,});}};

Changing the NavigationView size

By default,NavigationView uses all the available space provided to it. To adjust the size of the NavigationView, use thestyle prop.

<NavigationViewstyle={{width:200,height:50%}}.../>

Sample application

See theexample directory for a complete navigation sample app.

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 React Native 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 aMapView component, 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.

About

React Native library (Beta) for bringing Google Navigation SDK to Android and iOS apps using React.

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors9


[8]ページ先頭

©2009-2025 Movatter.jp