Overview
Rodando Driver uses the Google Maps JavaScript API with the Places library for map display and location services. The application dynamically loads the Google Maps script and configures it through theBaseMapComponent.
Prerequisites
Before configuring Google Maps in your application, you need:- A Google Cloud Platform account
- A project with billing enabled
- Google Maps JavaScript API enabled
- Places API enabled
- A valid API key
Google Cloud Console Setup
Create a Google Cloud Project
- Go to Google Cloud Console
- Click Select a project → New Project
- Enter a project name (e.g., “Rodando Driver”)
- Click Create
Enable Required APIs
Navigate to APIs & Services → Library and enable:
- Maps JavaScript API - For displaying maps
- Places API - For location autocomplete and place details
- Geocoding API (optional) - For address lookup
- Directions API (optional) - For route planning
Click on each API and press the Enable button.
Create an API Key
- Go to APIs & Services → Credentials
- Click + Create Credentials → API key
- Copy the generated API key
- Click Restrict Key to configure restrictions
Configure API Key Restrictions
For security, restrict your API key:Application Restrictions:
- For development: Select HTTP referrers and add
http://localhost:* - For production (Android): Select Android apps and add your package name and SHA-1 fingerprint
- For production (iOS): Select iOS apps and add your bundle identifier
- Select Restrict key
- Enable only:
- Maps JavaScript API
- Places API
- Any other APIs you’re using
Application Configuration
Environment Setup
Add your Google Maps API key to the environment files:The
&libraries=places parameter loads the Places library automatically. This is required for location autocomplete functionality.Map Component Configuration
TheBaseMapComponent (located at src/app/components/base-map/base-map.component.ts) handles Google Maps initialization:
src/app/components/base-map/base-map.component.ts
Map Options Reference
ThemapOptions object accepts the following configuration:
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string | Required | Your Google Maps API key |
disableDefaultUI | boolean | true | Hide all default UI controls |
gestureHandling | string | 'greedy' | Map gesture behavior ('greedy', 'cooperative', 'none') |
clickableIcons | boolean | true | Allow clicking on map POIs |
mapTypeControl | boolean | false | Show map type control (roadmap, satellite) |
zoomControl | boolean | false | Show zoom +/- buttons |
streetViewControl | boolean | false | Show street view control |
fullscreenControl | boolean | false | Show fullscreen button |
Gesture Handling Modes
- Greedy
- Cooperative
- None
- One-finger pan
- Two-finger zoom
- Best for mobile apps
- Currently used in Rodando Driver
Dynamic Script Loading
The application dynamically loads the Google Maps JavaScript API to optimize performance:src/app/components/base-map/base-map.component.ts
This approach prevents duplicate script loading and handles cases where multiple map components are used.
Using the BaseMapComponent
Incorporate the map component in your pages:Component Inputs
| Input | Type | Default | Description |
|---|---|---|---|
height | string | number | '400px' | Map container height |
width | string | number | '100%' | Map container width |
Advanced Configuration
Custom Map Styling
Add custom map styles to match your app’s theme:Enable Additional Controls
Set Initial Map Type
Places Library Integration
The Places library is loaded automatically via the API URL parameter:Using Places Autocomplete
Dependencies
Ensure you have the Angular Google Maps package installed:package.json
Testing Your Configuration
Test in Development
Start the development server:Navigate to a page with a map component and check the browser console for errors.
Check Network Requests
Open browser DevTools → Network tab and verify:
- Script loads from
maps.googleapis.com - No 403 (API key) or 429 (quota) errors
- Map tiles load successfully
Troubleshooting
API Key Errors
Error: “This page can’t load Google Maps correctly” Solutions:- Verify your API key is correct in
environment.ts - Check that billing is enabled in Google Cloud Console
- Ensure Maps JavaScript API is enabled
- Verify API key restrictions allow your domain/app
Quota Exceeded Errors
Error: “You have exceeded your daily request quota” Solutions:- Check usage in Google Cloud Console → APIs & Services → Dashboard
- Increase quota limits or enable billing
- Implement request caching to reduce API calls
- Use map load event listeners to prevent duplicate loads
Map Not Displaying
Symptoms: Gray box instead of map Solutions:- Check browser console for JavaScript errors
- Verify the map container has a defined height
- Ensure
isGoogleMapsLoadedistruebefore rendering - Check that center coordinates are valid
Places Library Not Loading
Error: “google.maps.places is undefined” Solutions:- Verify
&libraries=placesis in your API URL - Wait for script load before accessing Places API:
Security Best Practices
Configure API Restrictions
Limit API key usage to only required APIs (Maps JavaScript API, Places API).
Set Application Restrictions
- Development: Restrict to
localhost - Android: Add package name + SHA-1 fingerprint
- iOS: Add bundle identifier
Cost Optimization
Free Tier Usage
Google Maps Platform provides:- $200 monthly credit
- 28,000+ map loads per month (free)
- 100,000+ Places Autocomplete requests (free)
Optimization Tips
- Cache map instances - Don’t reload maps unnecessarily
- Lazy load - Only load maps when needed (current implementation)
- Use static maps - For non-interactive displays
- Debounce autocomplete - Reduce Places API calls
- Enable billing alerts - Monitor unexpected usage
Next Steps
Environment Config
Learn more about environment variable configuration
Capacitor Setup
Configure Capacitor for native mobile builds