Web Design Tutorials

How to Add a Google Map to Your Website

Written by Muhammad Naeem18 min readUpdated for 2026
A hand holding a smartphone showing a map with a navigation route
A hand holding a smartphone showing a map with a navigation route. Stock photo by cottonbro studio on Pexels (photo 4542998, free to use under the Pexels licence).

A map on your website answers the first question many visitors ask: where are you, and how do I get there? A customer who has to leave your site, open a maps app, and type your address by hand is a customer who may never come back. A map embedded right on your contact page removes that friction — they see your location, check the route, and tap for directions without ever leaving your site.

Adding a Google Map is one of the simplest upgrades a small business website can make. Google gives you a ready-made embed snippet you can paste into almost any website, and for anything fancier — custom markers, your own colours, or a map that talks to your booking system — there is a JavaScript API that gives you full control. This guide walks through both routes step by step, explains when to use each one, and covers the mistakes that leave people staring at a grey box instead of a map.

What Adding a Google Map Actually Means

There are two different things people mean when they say “add a Google Map to my website”, and picking the right one first saves you from rebuilding the work later. The first is an embedded map: a small live map window placed inside your page, usually on the contact page, showing your business location with a pin. Visitors can drag it, zoom it, and click through to Google Maps for directions. It is the right choice for most small business websites.

The second is a map built with the Google Maps JavaScript API. Instead of pasting a ready-made window, you write a small amount of JavaScript that loads the map and tells it exactly what to show: several locations at once, custom pin icons, your brand colours, info windows with opening hours, or a store locator that filters branches by postcode. It takes more setup — including a Google Cloud account and an API key — but it can do things an embed cannot.

A good rule of thumb: if you need one pin on one page, use the embed. If you need the map to react to your visitors — searching, filtering, or showing live data — use the API. Most of the businesses we build sites for never need more than the embed, and this guide starts there.

Before You Start: What You Need

Before you touch any code, gather three things. First, the exact address you want the pin to sit on. Check it in Google Maps first: search the address, and make sure the pin lands on your building and not on the street behind it or a similarly named business across town. If the pin is wrong in Google Maps, it will be wrong on your website too, and the fix happens in Google Maps, not on your site.

Second, a Google account. You need one to open Google Maps and copy the embed snippet, and you will need the same account (with billing enabled in Google Cloud) if you go the API route. Third, access to edit your website — either your content management system, your page builder, or the site files themselves. Know where your contact page lives and how to add an HTML block or snippet to it.

One more decision to make up front: where will the map live? For almost every business, the answer is the contact page, near your address, phone number, and opening hours. A map in the footer of every page looks helpful but slows every page down, and a map on the homepage pushes your main message down the screen. Put it where people look for directions — the contact page — and link to it from the footer if you like.

Method 1: Embed a Map with the Share Button

This is the fastest route, and it works on WordPress, Wix, Squarespace, Shopify, Webflow, and hand-built sites alike. You do not need a Google Cloud account, an API key, or a billing setup for this method.

  1. Open Google Maps in your browser and search for your business name or address. Wait until the pin is sitting in the right place.
  2. Click the Share button. A panel opens with two tabs: “Send a link” and “Embed a map”. Choose “Embed a map”.
  3. Pick a size. Google offers Small, Medium, Large, and Custom size. Choose Custom size and set the width to 100% so the map fills its container on every screen, and the height to around 400 pixels. A fixed pixel width will overflow on mobile phones, so the percentage width matters.
  4. Copy the HTML. Click “Copy HTML”. You now have a short snippet starting with <iframe ...>.
  5. Paste it into your page. In WordPress, add a Custom HTML block and paste the snippet. In Wix or Squarespace, use an Embed or Code block. On a hand-built site, paste it into the contact page HTML where you want the map to appear.
  6. Save and test. Load the page on a desktop and on a phone. Drag the map, zoom in and out, and click the pin to check it opens your business details.

That is the whole method. The embedded map updates itself when Google updates its maps, so your roads and place data stay current without any work from you. The trade-off is control: you cannot change the pin icon, hide parts of the interface, or restyle the colours. For a simple “find us” map, that trade-off is usually worth it.

Method 2: Build a Map with the JavaScript API

When the embed is not enough — you want several branches on one map, your own pin design, or a store locator — the Maps JavaScript API is the tool. It loads the map through JavaScript you control, so every part of it can be customised. The setup has more steps, so take them in order.

Step 1: Create a Google Cloud project. Go to the Google Cloud Console, sign in with your Google account, and create a new project for your website. Give it a clear name, such as the name of your business, so you can find it again later.

Step 2: Enable the Maps JavaScript API. Inside your project, open the API library, search for “Maps JavaScript API”, and enable it. If your map will also search for places or show directions, enable the Places API and Directions API in the same project.

Step 3: Create an API key. Go to Credentials, choose “Create credentials”, then “API key”. Google generates a long string of letters and numbers. Treat it like a password: it identifies your account, and anyone who has it can use your quota.

Step 4: Add the map to your page. Add a <div> with an id such as map and a fixed height, load the API script with your key, and write a small function that creates the map centred on your coordinates with a marker on your address. A minimal example looks like this:

<div id="map" style="height:400px;width:100%"></div>
<script>
  function initMap() {
    const office = { lat: 30.1575, lng: 71.5249 };
    const map = new google.maps.Map(
      document.getElementById("map"), {
        zoom: 15,
        center: office,
      }
    );
    new google.maps.Marker({ position: office, map: map });
  }
</script>
<script async src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap"></script>

Replace the latitude and longitude with your own — right-click any spot in Google Maps and choose the coordinates to copy them. And replace YOUR_API_KEY with the key you created in step 3.

Getting an API Key — and Keeping It Safe

An API key is the part of this process most people rush, and it is the part that causes the most trouble later. Google requires billing to be enabled on your Cloud project before the Maps API will work, even though Google includes a monthly free usage allowance that covers most small business websites. The allowance is generous: a single map on a contact page typically stays well inside it. But billing must be switched on, or the map will not load at all.

Once the key exists, restrict it before you put it on a live website. In the Cloud Console, open your key and set two restrictions. First, an application restriction: choose “HTTP referrers” and add your domain, such as *.yourwebsite.com/*, so the key only works when the request comes from your site. Second, an API restriction: limit the key to only the APIs you enabled, such as the Maps JavaScript API. A restricted key is useless to anyone who copies it from your page source, because it will not work from any other website.

Two habits will save you from surprise bills. Set a daily quota limit or a budget alert in the Cloud Console so you get an email if usage spikes — a spam bot hammering your contact page should never be able to run up a large charge unnoticed. And rotate the key if it ever appears in a public place it should not, such as a screenshot, a forum post, or a public code repository. Creating a replacement key takes a minute; cleaning up after a stolen one takes much longer.

Adding Markers, Info Windows, and Business Details

A bare map with a red pin is useful, but a map that tells visitors something is better. With the API, an info window is a small popup that appears when someone clicks a marker. Put your business name, address, phone number, and opening hours in it, plus a link to get directions. Keep the text short — an info window is a label, not a second contact page.

Custom markers are another easy win. A pin in your brand colour, or a small logo marker, makes the map feel like part of your website instead of a widget dropped in from somewhere else. Keep the marker simple and readable at small sizes: a filled shape with a clear symbol works far better than a detailed image that turns into a blur on a phone screen.

If you have more than one location, plot them all on the same map and let visitors click each one. For a handful of branches, hard-code the markers. For dozens, load them from a list or a spreadsheet so adding a new branch does not mean editing your page code. And remember that the map is a supplement to your written address, not a replacement for it: always show the address as plain text beside the map, so visitors can copy it, search engines can read it, and the page still makes sense if the map fails to load.

Styling the Map to Match Your Website

A default Google Map is bright, colourful, and instantly recognisable — which is exactly the problem on a carefully designed website. The API lets you restyle the map with a JSON style definition: mute the road colours, hide points of interest you do not need, or match the map to a dark theme. Google offers a map style editor where you can preview changes live and export the finished style as JSON to paste into your code.

Restraint matters more than creativity here. A map still needs to be readable as a map. Keep roads visible, keep labels legible, and keep enough contrast that a visitor can tell a park from a car park. The goal is a map that fits your site without making anyone work harder to read it.

If you used the embed method, styling options are limited. You can still frame the map well: give its container rounded corners, a subtle border, and spacing that matches the rest of the page. A CSS filter can dim or desaturate an embedded iframe, but use it lightly — heavy filters make the map harder to read and can look like a mistake rather than a design choice.

Making the Map Mobile-Friendly and Fast

Most visitors who need your map are on a phone, often standing outside looking for you. That makes mobile behaviour the real test. The most common mobile failure is a map that is wider than the screen, forcing sideways scrolling. The fix is simple: set the map container to 100% width and a fixed height, and never set a fixed pixel width on the iframe or the div.

The second mobile problem is touch. A map that captures every finger swipe makes the page impossible to scroll past — the visitor tries to scroll down and the map zooms instead. With the API, set the gesture handling option so the map only responds to two-finger gestures on touch screens, or require a click before the map becomes interactive. With an embed, you can wrap the iframe in a container that only enables pointer interaction after a tap, or place a “ tap to interact” overlay on top of it.

Speed matters too. A Google Map loads scripts, tiles, and fonts — it is one of the heaviest things you can put on a page. Do not load it at the top of the page, and do not load it on pages that do not need it. Keep it on the contact page, and consider lazy loading: show a static image or a simple button first, and load the live map only when the visitor scrolls to it or taps it. On a contact page that is a fair trade; on a homepage it is essential.

Common Problems and How to Fix Them

When a map breaks, it usually breaks in one of a few recognisable ways. Here are the ones we see most often, and what each one means.

  • Grey box, no map. The map container has no height. A div with no content collapses to zero height, so the map loads into an invisible box. Give the container an explicit height in CSS — 400 pixels is a good starting point — and the map will appear.
  • “For development purposes only” watermark. This appears when the API key is missing, invalid, or the project has no billing enabled. Check the key, check that billing is enabled on the project, and check the browser console for the exact error message.
  • “This page can't load Google Maps correctly.” Usually an API that is not enabled, or a key restricted to the wrong referrer. Open the Cloud Console, confirm the Maps JavaScript API is enabled, and check that your domain is listed in the key's HTTP referrer restrictions.
  • The pin is in the wrong place. The coordinates or the searched address are wrong. Search the address in Google Maps, right-click the correct spot, copy the coordinates, and update the marker position. If the place itself is misplaced in Google, suggest an edit in Google Maps.
  • The map works on desktop but not on mobile. Almost always a width problem: a fixed pixel width on the iframe, or a container wider than the viewport. Switch the width to 100% and test on a real phone, not just a resized desktop browser.
  • The map loads slowly. Move the script to load after the rest of the page, or lazy-load it as described above. A map that loads last never blocks your headline, your contact details, or your call button.

When in doubt, open your browser's developer console (F12) and read the error. Google's Maps errors are unusually specific — they usually name the exact problem, whether it is a missing API, a bad key, or a billing issue — and that message tells you which of the steps above to repeat.

Privacy and Consent: What to Tell Visitors

A Google Map is not just a picture: it loads scripts from Google's servers, and those scripts can set cookies and collect usage data. In regions with strict privacy rules, such as the European Union, that counts as loading third-party content, and many websites handle it the same way they handle other embeds — by loading the map only after the visitor accepts the relevant cookies, or by showing a placeholder with a “click to load the map” button.

A click-to-load placeholder has a second benefit: it makes your page faster, because nothing from Google loads until the visitor asks for the map. The placeholder can be a simple static image of the area with your address written underneath, which is useful on its own even before anyone clicks.

This is general information, not legal advice. Privacy rules differ by country and change over time, and if a large share of your visitors come from the EU or other regulated regions, it is worth checking the current requirements for your situation — or asking a professional — rather than guessing. What matters for most small business sites is the principle: do not silently load third-party tracking content, and give visitors a clear choice.

Map Alternatives Worth Knowing

Google Maps is the default choice because visitors already know how to use it, but it is not the only option. OpenStreetMap is a free, community-built map with its own embed option: you can paste a small iframe into your page with no account and no API key. The maps look plainer and fewer visitors will recognise the interface, but there are no usage bills and no key to manage. It is a solid choice for a simple “find us” map on a tight budget.

Another option is a static map image: a screenshot or an exported image of your location, linked to Google Maps so clicking it opens directions. It loads instantly, costs nothing, and never breaks — but visitors cannot drag or zoom it, so it works best as a complement to a live map rather than a replacement.

Some website builders also offer their own map blocks — Wix, Squarespace, and Shopify all have one — which are simply the Google embed wrapped in a friendlier panel. If your builder offers one, use it: it handles the sizing and mobile behaviour for you, and you can switch to the manual embed later if you outgrow it.

Whatever you choose, keep the written address next to the map. A map helps people who can see it; the address helps everyone else, including search engines, screen readers, and visitors on a slow connection where the map never loads.

Conclusion

Adding a Google Map to your website is a small job with an outsized effect: it turns a contact page from a list of details into a working tool that gets people to your door. Start with the embed method — it takes a few minutes, needs no API key, and covers what most businesses need. Move to the JavaScript API only when you have a specific reason: several locations, custom styling, or a locator that reacts to visitors. Whichever route you take, restrict your API key if you use one, test the map on a real phone, keep the written address beside it, and check that the pin sits on the right building before you publish. A map that points to the wrong place is worse than no map at all.

If you would like the map added to your site properly — embed or API, styled to match your design, and tested on mobile — get in touch with Naeem Web Studio and we will set it up for you.

Frequently Asked Questions

Can I add a Google Map to my website for free?

Yes. The embed method is free and needs no API key or billing setup — you copy the snippet from Google Maps and paste it into your page. The JavaScript API also includes a monthly free usage allowance that covers most small business sites, but it does require billing to be enabled on your Google Cloud project before it will work.

Do I need an API key to embed a Google Map?

No. The Share > Embed a map snippet works without any key. You only need an API key if you build the map with the Maps JavaScript API, for example to add custom markers, several locations, or your own styling.

Why is my Google Map showing a grey box?

The most common cause is a map container with no height — a div with no content collapses to zero, so the map loads into an invisible box. Give the container an explicit height, such as 400 pixels, and the map should appear. If the box shows a watermark message instead, the API key or billing setup is the problem.

Will a Google Map slow down my website?

It can. A live map loads scripts, tiles, and fonts, so it adds weight to the page. Keep the map on the contact page only, and consider lazy loading it — show a placeholder first and load the live map when the visitor scrolls to it or taps it.

How do I put a pin on my exact business location?

In Google Maps, search for your address and check the pin sits on your building. For the embed method, the pin follows the place you shared. For the API method, right-click the exact spot in Google Maps, copy the coordinates, and use them as the marker position in your code.

Is it better to use Google Maps or OpenStreetMap on my website?

Google Maps is the better choice for most businesses because visitors already know how to use it, and the embed is free and simple. OpenStreetMap is worth considering if you want a map with no account, no API key, and no usage billing, and you are happy with a plainer map that fewer visitors will recognise.

Need a Map on Your Website?

We add Google Maps to business websites — embedded or custom-built — styled to match your design and tested on mobile. Tell us where your business is, and we will handle the setup.

WhatsApp: 03207140898Send Email Inquiry

Explore More Resources & Services:

Google Business Profile Setup GuideLocal SEO Checklist for Small BusinessHow to Add a Contact Form to Your WebsiteHow to Add a WhatsApp Chat Button to Your WebsiteHow to Add a Sitemap to Your WebsiteWebsite Speed and Conversions Guide
Chat with Naeem