duda
5 ways to add responsive Google Maps to your website

Shawn Davis • May 14, 2020


Once in a while, you may have a web design customer ask specifically about responsive Google Maps. Now if you’re already familiar with Duda’s platform, you’ll know its professional-grade website builder comes with a fantastic  responsive map widget powered by Mapbox. We love Mapbox because it allows for easy integration into mobile and online applications, and is highly adaptable to new map designs and layouts. Not to mention, it has great global coverage.


That being said, if a Google Map is required for a project, you’re still covered. Duda’s flexible platform enables you to easily add nearly any kind of map you and your customers would like to use.


With this in mind, we decided to produce this in-depth guide to help you navigate the sometimes tricky world of Google Maps with ease, offering up all the options available as well as details as to why you may use them.


A little about Google Maps


More than 150 million users access Google Maps monthly.  Adding a responsive Google Maps widget can help consumers locate your customers’ businesses, gives credibility to their organizations, and improves the overall user experience. Embedding a map on your site can also reduce the bounce rate and helps with your search engine optimization efforts. 


Google Maps are interactive by default, and Google makes it easy to integrate them into websites. However, Google Maps are not responsive by default, which means it doesn’t automatically resize based on the device screen size. Additional programming is needed to make automatic resizing possible. 


Do you have to pay for Google Maps to put it on a website?  Yes and no. Basic embedding is free and includes a simple view, a map pin, and your business information.For more complex functions, however, a fee is attached. For example, in order to display multiple locations or implement more advanced features like Google Street View , finding routes, and searching places, Google starts charging once usage quotas are reached.


If you’re interested, click here to learn more about how Google API billing works. Otherwise, let’s talk about working with responsive Google Maps. 


Why should I integrate Google Maps into my website?


One of the first questions you may have is why would you want to integrate Google Maps into your website in the first place. Well, there are actually many reasons, and while it will increase credibility, as we’ve already stated, it can also boost your site in many other areas too. This could include:


Enhancing your contact page


For the most part, websites will use Google Maps on their contact page in order to highlight where their physical locations are. This adds a little more context for those who potentially want to visit the location, with roads, routes and local landmarks all visible.


Highlighting routes


It may be that you want to highlight a particular route on Google Maps. There are many reasons for this, from hiking or running routes to telling a story of a particular journey, which is especially useful for travel sites and blogs.


Store locators


Alongside highlighting your physical location, eCommerce businesses can effectively integrate Google Maps into their site on store locator pages, which highlights the nearest stock of a particular product.


There are of course many other reasons too. Their aim is simple, to provide a visual overlay of the information you’re trying to get across, and with Google looking more and more for in-depth and useful features within the pages it ranks, it can be an excellent way to meet a user’s search intent.


How do I embed Google Maps into my website?


Embedding Google Maps in any website can be done in a variety of ways.  A novice can handle most of the code, although some knowledge of HTML, CSS, and JavaScript is helpful. Google provides the code and there are several ways to embed responsive Google Maps into any website using iframes. In this post we will address several DIY methods by describing step-by step-procedures on how to embed responsive maps in any website platform, including Duda and others.


Google maps integration using Google's embeddable iframe code


One of the best ways to integrate Maps into your site is with an Iframe code. It’s the simplest way, especially if you aren’t too clued up on website building. Below you’ll find full information on how to copy the Google embed code from Google Maps into a site’s HTML code.  No other code of formatting is applied or required.


1. Obtain a Google Maps embed code


  • Go to Google Maps
  • Enter the business address in the search bar, then click the search button
  • Click on the Share icon
  • Choose "Embed map"
  • Select the size of the map from the drop down
  • Select and copy the HTML iframe embed code


A screenshot of Google Maps showing the


2. Paste the embed code into your HTML page or widget


The code should look like the block below. You should paste this code directly into a website's HTML or, if using Duda, into the HTML Widget.

 

<iframe src="YOUR GOOGLE MAPS URL" width="600" height="450" style="border:0;" allowfullscreen="" loading="lazy" referrerpolicy="no-referrer-when-downgrade"></iframe>

The resulting map has a static width and height of "600" and "450" pixels respectively.  The size may be adjusted by changing the width and height attributes, but this map is not a responsive Google Map element, so it won't automatically resize on various devices. To make a responsive map, we need to dive a bit deeper.

Screenshots of Google Maps embedded into a Duda website using an iFrame as-is. The screenshots are presented in three sizes: desktop, tablet, and phone.

Create a responsive Google Maps widget without an API Key


There are other ways though, and some people prefer to take them and move away from iframes. It’s entirely possible to embed a responsive Google Map into a website without using a Google Map API.  Here’s how you do it.  


1. Obtain a Google Maps embed code


  • Go to Google Maps
  • Enter the business address in the search bar, then click the search button
  • Click on the Share icon
  • Choose "Embed map"
  • Select the size of the map from the drop down
  • Select and copy the HTML iframe embed code


2. Paste the embed code into your HTML page or widget


 

<iframe src="YOUR GOOGLE MAPS URL" width="600" height="450" style="border:0;" allowfullscreen="" loading="lazy" referrerpolicy="no-referrer-when-downgrade"></iframe>

3. Modify the embed code



Add a CSS class called map-responsive around the iframe as follows:

 

<div class="map-responsive">

<iframe src="YOUR GOOGLE MAPS URL" width="600" height="450" style="border:0;" allowfullscreen="" loading="lazy" referrerpolicy="no-referrer-when-downgrade"></iframe>

</div>

4. Edit your site's CSS file



Add the following CSS to your site's .css file:

 

.map-responsive{

    overflow:hidden;

    padding-bottom:56.25%;

    position:relative;

    height:0;

}

.map-responsive iframe{

    left:0;

    top:0;

    height:100%;

    width:100%;

    position:absolute;

}

You can change the height of the map by adjusting the padding-bottom value like this: padding-bottom: 40%;


Screenshots of Google Maps embedded into a Duda website using an iFrame wrapped in a container with custom CSS applied. The screenshots are presented in three sizes: desktop, tablet, and phone.


You now have a responsive Google Map without using an API key. This method of embedding and CSS styling should work for any HTML based website. Learn how to use media queries for standard devices here.


How to embed a responsive Google Maps widget without Google APIs or further CSS styling


Although this type of responsive Google Maps integration may be required for older platforms like WordPress, the Duda HTML widget makes the implementation of responsive Google Maps very simple and fast if you want to embed one in a Duda website template. There are only a couple of things to do.


1. Obtain a Google Maps embed code


  • Go to Google Maps
  • Enter the business address in the search bar, then click the search button
  • Click on the Share icon
  • Choose "Embed map"
  • Select the size of the map from the drop down
  • Select and copy the HTML iframe embed code


2. Paste the embed code into your HTML page or widget


 

<iframe src="YOUR GOOGLE MAPS URL" width="100%" height="100%" style="border:0;" allowfullscreen="" loading="lazy" referrerpolicy="no-referrer-when-downgrade"></iframe>

Changing the width and height of the iframe to 100% will allow the Google Maps embed to completely encompass the HTML widget container, making it responsive and easy to resize on any device.  No further CSS styling or media query usage is necessary when using this method.

Screenshots of Google Maps embedded into a Duda website using an iFrame with the width and height set to 100%. The screenshots are presented in three sizes: desktop, tablet, and phone.

Embed a Google Maps widget using javascript via the Google Maps API


Google Maps can be integrated into a website via APIs. In addition to HTML and CSS, knowledge of JavaScript is required.  Although our example is quite simple, the Google Maps platform provides complex features including drawing map markers, calculating distance and areas, displaying prominent points of interest, heatmaps, and more.  You can find more details in the Google Maps libraries.


1. Create an API key


  • Go to the Google Cloud Platform Console
  • Select or create the project for which you want to add an API key
  • Select APIs & Services > Credentials
  • Click Create credentials > API Key


It’s important to restrict the API key before using it in production. Restrictions provide added security and help ensure that only authorized requests are made with your API key.


2. Add the scripts and your API key


Add the map styling code to your page:


 

<style>

 #map {

    width: 100%;

    height: 400px;

    background-color: grey;

}

</style>

Add the map script that propagates the map element, and edit coordinates:

 

<script>

    function initMap() {

      var macc = {lat: 42.1382114, lng: -71.5212585};

      var map = new google.maps.Map(

          document.getElementById('map'), {zoom: 15, center: macc});

      var marker = new google.maps.Marker({position: macc, map: map});

    }

 </script>

Add Google Maps' API script:

 

<script 

   async

   defer

   src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap">

</script>

Now you have a responsive map created using Google Maps JavaScript API!

Screenshots of Google Maps embedded into a Duda website using Google’s API. The screenshots are presented in three sizes: desktop, tablet, and phone.

Embed a Google Maps widget using third-party solutions


Sometimes, you just don’t feel like messing around with code and want a ready made widget. Well, good news! TheCamel.co, a long-time Duda partner, created a Google Map widget  specifically for use on the Duda platform. This widget works great for local businesses that have multiple locations and has advanced features like theme and pin customizations, logo and business info display, and zooming for street and map view. 

Two screenshots showing TheCamel.co's Google Maps widget, one a regular map and the other


When it comes to Google Maps integration, there are multiple ways to get the job done. They range from DIY methods for a simple map integration and custom widgets to advanced JavaScript Google Map API implementation.


Remember: If you don’t want to write code and you need multiple locations, a professional web design platform like Duda makes it very easy to intuitively add advanced code via widgets. And if you want to avoid coding altogether,  you can find the right developer through Duda’s Expert Program.


Google Maps  offers APIs, SDKs and many step-by-step tutorials and code samples to help users create simple responsive Google Maps or highly customized maps which can do all sorts of cool stuff. With just a few steps, you can augment your site with an array of functionality from a simple map view through highly complex and interactive mapping tools.

The homepage for Duda.co
By Renana Dar 22 Apr, 2024
We sat out to redesign Duda's homepage using the most advanced capabilities of our own platform. See how we combined design, code, and advanced drag-and-drop capabilities to create a homepage like no other.
Three cards with a picture of a chair on them
By Shawn Davis 19 Apr, 2024
There exists a maximum number your customers are willing to pay, but finding that number is no easy task. Here’s everything your SaaS company needs to know about uncovering this elusive metric.
A byline article by Itai Sadan published by Entrepreneur showing a stack of money and a headline.
By Itai Sadan 16 Apr, 2024
Studies show most incorrectly priced products are priced too low. Learn to bridge the gap between actual and perceived value, identify maximum customer willingness-to-pay and adopt metric-based pricing for increased profitability.
Show More

Latest Posts

Share by: