Quickstart
This guide will help you render your first route on a map using react-native-maps-routes.Prerequisites
Before starting, make sure you’ve completed the Installation guide:- react-native-maps-routes is installed
- react-native-maps is configured for your platform
- You have a valid Google Maps Routes API key
Build your first route
Import the component
Import
MapViewRoute from react-native-maps-routes along with the necessary components from react-native-maps:Render the route inside MapView
Create a
MapView component and render MapViewRoute as a child. Pass the required props:Complete example
Here’s the complete working example:How it works
When you renderMapViewRoute:
- The component makes a request to the Google Maps Routes API with your origin and destination coordinates
- The API computes the optimal route based on the travel mode (defaults to
WALK) - The route polyline is decoded and rendered as a
Polylinecomponent on the map - The route automatically updates when you change the origin, destination, or other route parameters
By default, routes use the
WALK travel mode. You can change this by setting the mode prop to DRIVE, BICYCLE, or TWO_WHEELER.Customize your route
You can customize the route appearance and behavior with additional props:- Uses driving directions (
mode="DRIVE") - Draws the route in red (
strokeColor="#FF0000") - Uses a thicker line (
strokeWidth={5}) - Logs when the route is ready
- Handles errors gracefully
Next steps
Now that you have a basic route working, explore more advanced features:Add waypoints
Add intermediate stops along your route
Travel modes
Configure driving, walking, cycling, or two-wheeler routes
Route modifiers
Avoid tolls, highways, ferries, or indoor steps
Get ETA and distance
Fetch estimated travel time and route distance