Installation
This guide walks you through installing react-native-maps-routes and setting up the required Google Maps Routes API key.Install the package
Install react-native-maps-routes using your preferred package manager:Peer dependencies
react-native-maps-routes requires the following peer dependencies. Make sure they are installed in your project:- react: Any version (
*) - react-native:
>=0.64.3 - react-native-maps:
>=1.0.0
react-native-maps requires additional native configuration. Follow the react-native-maps installation guide to complete the setup.
Google Maps Routes API key setup
react-native-maps-routes uses the Google Maps Routes API to compute routes. You’ll need a valid API key with the Routes API enabled.Step 1: Create or use an existing API key
If you don’t have a Google Maps API key:- Go to the Google Cloud Console
- Create a new project or select an existing one
- Navigate to APIs & Services → Credentials
- Click Create Credentials → API Key
- Copy your new API key
Step 2: Enable the Routes API
If you’re using an existing Google Maps API key, you must enable the Routes API:- Go to the Google API Console
- Select your project
- Click Enable APIs and Services
- Search for “Routes API”
- Click Enable
Step 3: Review API pricing
The Google Maps Routes API is a paid service with usage-based pricing. Review the Routes API pricing to understand costs. Key points:- You can optimize costs by requesting only the fields you need using
legFieldsandlegStepFields - The library automatically generates minimal field masks to reduce API costs
- Consider implementing caching strategies for frequently requested routes
Environment variables
For security, store your API key in environment variables instead of hardcoding it:.env
You’ll need to configure your React Native project to read environment variables. Popular options include react-native-config or react-native-dotenv.
Verify installation
To verify your installation is complete:- All peer dependencies are installed
- react-native-maps is configured for your platform (iOS/Android)
- You have a valid Google Maps Routes API key
- The Routes API is enabled in your Google Cloud project
TypeScript support
react-native-maps-routes is written in TypeScript and includes full type definitions. No additional@types packages are needed.
The library exports the following types: