By integrating the Navigation SDK for Android, your app can go beyond linking to an external map view. With Google Maps navigation, your app can offer dynamic retrieval and single-look reporting of data about a driver's journey.
This guide presents you with an Android Studio project, shows you how to integrate the Navigation SDK, and then shows you how to run the demo applications.
The Navigation SDK is a static library (.aar) that gives you control over the appearance and audio for navigation in your app. For details about the library, open Navigation SDK reference (Javadoc) in a separate window.
Get ready
To get started with the Navigation SDK, be sure to have the following items.
A Google Maps Platform representative for access to the following:
- An API key provisioned for use with Navigation SDK. You need to provide your projectID which you can find in the Google Cloud Console main dashboard, under the project name.
The SDK artifact
- Ensure that your project is configured to use Maven for the Navigation SDK.
- If you cannot use Maven, you can download the zipped artifact from the
shared Google Drive. The static library file is the
.aar in the
libs/
directory containing the Navigation SDK as an AAR bundle.
One or more of the demo apps
Android Studio, the recommended development environment for building an app with the Navigation SDK. This documentation is designed for people familiar with Android development and object-oriented programming concepts. You should also be familiar with Google Maps from a user's point of view.
Get the Demo apps
As of Navigation SDK for Android v4.1, the following demo apps let you test out features in the SDK. They are both available in the shared Google Drive to download.
GoogleNavigation demo: showcases the integration of API behaviors and views as they pertain to the user's experience while in a guided-navigation session.
GoogleMap demo: showcases individual behaviors of the
GoogleMap
interface to customize the feel and presentation of maps.
A note on using Maven
The demo apps are configured to download the SDK artifact from the remote Maven repository, using the Artifact Registry plugin in Gradle. Make sure to follow the project configuration instructions to gain access to the SDK.
The GoogleNavigation demo
The latest GoogleNavigation demo is available at the root of the shared Google Drive. Previous versions of the app exist in the "Archive." For versions prior to 4.1, the app is bundled alongside the AAR in the same zip file.
Building
In Android Studio, import the demo app and allow Gradle to run.
Open
local.defaults.properties
and update the value of theMAPS_API_KEY
property:MAPS_API_KEY=YOUR_API_KEY
Click build and examine the SDK implementation details.
In the java class, note the implementation code.
In the layout xml, note the layout design and text.
In the
build.gradle
file, note the SDK in the dependencies.
See the Secrets Gradle plugin documentation for more information on how the API key is added to the manifest.
Running
Connect an Android device to your computer or use an emulator.
- Android device Refer to the instructions to enable developer options on your Android device and configure your system to detect the device.
- Emulator Use the Android Virtual Device (AVD) Manager to configure a virtual device. When choosing an emulator, make sure you pick an image that includes the Google APIs.
In Android Studio, click the Run menu option (or the play button icon); and then choose a deployment target.
When built and launched, the app presents the user with a landing page of a list of options.
NavViewActivity and NavFragmentActivity options
New adopters of the NavSDK will likely find these two options to be the most useful.
Option 1: NavViewActivity
showcases behaviors using the
NavigationView
in conjunction with the Navigator
.
Option 2: The second option, titled NavFragmentActivity
, showcases behaviors using the
SupportNavigationFragment
alongside the Navigator
.
When you click one of these options, you'll be presented with the following:
- the navigation UI
- a "Set Destination" button in the app's menu
- an overlay that you can interact with to dynamically invoke methods on the API
- an overflow menu with more options
To get started, click Set Destination and pick an address. The app then simulates a trip from your current location to that address. Use the control panels overlay to see what happens when you call an API. For instance, you can click View Methods to try forcing the SDK into night-mode to see what it looks like.
SwappingMapAndNavActivity option
The SwappingMapAndNavActivity
showcases the following common
patterns:
- displaying a
MapView
- swapping to a
NavigationView
when navigation begins - returning to a
MapView
when navigation ends
The GoogleMap demo
The latest GoogleNavigation demo is available at the root of the shared Google Drive. Previous versions of the app exist in the "Archive."
Building
In Android Studio, import the demo app and allow Gradle to run.
Open
local.defaults.properties
and update the value of theMAPS_API_KEY
property:MAPS_API_KEY=YOUR_API_KEY
Click build and examine the SDK implementation details.
In the java class, note the implementation code.
In the layout xml, note the layout design and text.
In the
build.gradle
file, note the SDK in the dependencies.
secrets gradle plugin for more information on how the API key is added to the Manifest.
Running
Connect an Android device to your computer or use an emulator.
- Android device Refer to the instructions to enable developer options on your Android device and configure your system to detect the device.
- Emulator Use the Android Virtual Device (AVD) Manager to configure a virtual device. When choosing an emulator, make sure you pick an image that includes the Google APIs.
In Android Studio, click the Run menu option (or the play button icon); and then, choose a deployment target.
When built and launched, the app presents the user with a landing page of a list of demos. Previous users of the Maps API on Android will find this presentation pattern, and the corresponding structure of the source code, familiar.
This is because the GoogleMap demo is designed to be similar to the Maps API
demo app. The primary difference
is that we include a toggle to let the user choose which view class they'd like
to test-run a demo on: NavigationView
or MapView
,
where applicable.
We generally encourage adopters to use the NavigationView
, but want to give
you the flexibility to try these behaviors on both versions in our sampleapp
and choose whichever works for you. For example, it may still be necessary
to use a MapView
in situations where you are using a third-party library that
expects to interact with that class.