If your custom Google Maps implementation on Webflow isn't working properly, the issue is typically due to incorrect API setup, invalid coordinates, or script integration errors.
1. Ensure You Have a Valid Google Maps API Key
- Go to the Google Cloud Console and create a project (if you haven’t already).
- Enable the following APIs:
- Maps JavaScript API
- Geocoding API (optional, if converting addresses to coordinates)
- Create an API key under “Credentials”.
- Restrict the key to work only on your Webflow domain (e.g.,
*.yourdomain.com
). - Copy the key for use in your embed code.
2. Add the Correct Embed Code to Webflow
- Use an Embed element inside your Webflow page where the map should appear.
- Ensure your embed code includes your API key (typically as
key=YOUR_API_KEY
in the script URL). - Make sure you're defining a valid div container (e.g.,
<div id="map"></div>
) and initializing the map within a proper <script>
tag. - Load the map with proper initialization, referencing valid coordinates like this:
center: { lat: 40.7128, lng: -74.0060 }
(New York City, for example)
3. Verify the Coordinates
- Use decimal format for coordinates (e.g.,
37.7749, -122.4194
for San Francisco). - Confirm the coordinates are passed as numbers, not strings.
- Use Google Maps manually to find precise latitude and longitude for the location you want.
4. Check Developer Console for JavaScript Errors
- Preview the published site and open Chrome DevTools (Cmd + Option + I on Mac, Ctrl + Shift + I on Windows).
- Look for messages like “Google Maps JavaScript API error: InvalidKeyMapError” or “initMap is not defined”.
- These errors usually point to missing API keys, lack of billing setup, or syntax problems in your map code.
5. Enable Billing in Google Cloud Console
- Google Maps requires billing to be enabled, even for free-tier usage.
- Go to Billing > Link your project to a billing account.
- Without billing, your map won’t load and will typically display a “For development purposes only” watermark or a blank space.
6. Use Lazy Loading and Custom Script Timing
- If map initialization runs before the element loads, it will fail.
- Wrap your initialization inside a
window.onload
or place the script inside Webflow's Footer Custom Code section to ensure it runs after the page loads.
Summary
To fix your custom Google Maps in Webflow, ensure you’ve set up a valid API key with billing, include the correct initialization script, use properly formatted coordinates, and check browser console logs for errors. Most issues come from API key misconfiguration or scripts running before the map container is available.