Integrating Google Maps into a Webflow CMS template page using dynamic data involves a few steps. Here's how to achieve this:
<div id="map" style="height: 500px;"></div>
<script>
function initMap() {
var geocoder = new google.maps.Geocoder();
var address = "{{CMS Address Field}}"; // Replace with your collection field
geocoder.geocode({'address': address}, function(results, status) {
if (status === 'OK') {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 15,
center: results[0].geometry.location,
styles: // Paste your Snazzy Maps styles here
});
new google.maps.Marker({
position: results[0].geometry.location,
map: map
});
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_GOOGLE_MAPS_API_KEY&callback=initMap" async defer></script>
YOURGOOGLEMAPSAPIKEY with your actual Google Maps API key.{{CMS Address Field}} with Webflow’s dynamic data element that pulls the address from your CMS.
To add Google Maps with dynamic addresses on Webflow CMS pages, integrate Google Maps API with a Snazzy Maps theme by using a dynamic embed. Ensure your CMS collection is set up correctly, get an API key, paste the map code in a dynamic embed, and publish your site for testing.