Launching Google Maps Directions via an intent on Android
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Android developers often need to integrate popular external functionalities, including maps and navigation, into their applications. One such feature is opening route directions in Google Maps using an Intent. This capability enhances user experience by providing detailed navigation directly through the well-established Google Maps platform.
What is an Intent?
In Android, an Intent is a messaging object you can use to request an action from another app component. While there are several types of intents, one common use is to start an activity in another app by defining an intent with a specific action.
Launching Google Maps Directions
To open Google Maps and show directions using an Intent, you will need the Google Maps package com.google.android.apps.maps and an action to view the specific data – in this case, the data is geolocation information constituting directions.
Step-by-Step Implementation:
- Define the Uri: Create a URI that Google Maps can understand. Google Maps accepts the
geo:URI scheme for showing locations.
- Create an Intent: Once the URI is defined, create an Intent to handle this URI. The action to be used here is
Intent.ACTION_VIEW.
- Verify and Start Activity: Before actually starting the activity, it’s good practice to check if any app can handle it. This is crucial for avoiding crashes.
Parameters to Customize Directions
The basic URI to start directions uses just latitude and longitude, but Google Maps supports various other parameters that can enhance and tailor the directions better:
- Mode of Travel: By appending
&mode=dto the uri, you can set modes like driving (d), walking (w), bicycling (b), or transit (r). - Avoidances: You can also specify avoidances like
&avoid=tolls|highways|ferries. - Waypoints: Adding
&waypoints=lat,lng|lat,lng…can define intermediate stops.
Practical Example
Suppose you want to start navigation in Google Maps to the Empire State Building, you would define the URI as follows:
Special Considerations
- Permissions: No additional permissions are required to launch Google Maps using an intent for directions.
- Google Maps App: This functionality presumes that Google Maps is installed on the device. If not, the intent resolution will fail, and you need to handle this gracefully.
Summary Table
| Feature | Description | Example |
| URI Scheme | Defines the format for a Google Maps URI | geo:latitude,longitude |
| Modes | Specifies the type of navigation | &mode=d for driving |
| Avoidances | Criteria to exclude certain routes | &avoid=tolls to avoid toll roads |
| Action | Android Intent action to view the directions | Intent.ACTION_VIEW |
Conclusion
Integrating Google Maps directions using an Intent in Android applications is straightforward yet powerful. By crafting a URI according to Google Maps' specifications and creating an appropriate Intent, you can provide rich, familiar navigation support within your app. This enhances user convenience by leveraging one of the most comprehensive mapping tools available.

