Your Google Maps API key is being detected but is invalid. Here's how to fix it:
- Go to Google Cloud Console: https://console.cloud.google.com/
- Create a new project or select an existing one
- Enable the required APIs:
- Maps JavaScript API
- Geocoding API
- Directions API
- Places API (if needed)
- Create credentials:
- Go to "APIs & Services" > "Credentials"
- Click "Create Credentials" > "API Key"
- Copy the generated API key
-
Set up HTTP referrers (recommended for security):
- Click on your API key
- Under "Application restrictions" select "HTTP referrers"
- Add your domains:
localhost:* *.vercel.app *.netlify.app yourdomain.com/*
-
Enable billing (required for Google Maps API):
- Go to "Billing" in Google Cloud Console
- Link a billing account to your project
- Google Maps API requires billing to be enabled
Create a .env file in your FrontEnd directory:
VITE_GOOGLE_MAPS_API_KEY=your_actual_api_key_here
VITE_API_BASE_URL=https://offcampusrooms.onrender.comUpdate FrontEnd/src/config/env.js:
export const GOOGLE_MAPS_API_KEY = 'your_actual_api_key_here';- Restart your development server
- Check the console for these messages:
✅ Using VITE_GOOGLE_MAPS_API_KEY from environment 🔑 RideBooking - Google Maps API Key Status: {hasKey: true, keyLength: 39, keyPreview: 'AIzaSy...'}
- Go to your Vercel project settings
- Add environment variable:
- Name:
VITE_GOOGLE_MAPS_API_KEY - Value: Your actual API key
- Name:
- Redeploy
- Go to Site settings > Environment variables
- Add:
- Key:
VITE_GOOGLE_MAPS_API_KEY - Value: Your actual API key
- Key:
- Redeploy
-
"InvalidKeyMapError":
- Check if billing is enabled
- Verify API key is correct
- Ensure required APIs are enabled
-
"ReferrerNotAllowedError":
- Add your domain to HTTP referrers
- Include both
wwwand non-wwwversions
-
"QuotaExceededError":
- Check your billing account
- Monitor usage in Google Cloud Console
You can test your API key by visiting:
https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap
If it loads without errors, your key is working.
- Never commit your API key to version control
- Use environment variables for production
- Set up proper HTTP referrer restrictions
- Monitor your API usage regularly
Google Maps API has a generous free tier:
- $200 monthly credit
- Typically covers thousands of map loads
- Monitor usage in Google Cloud Console