Knowledge base / Embeds

Replace a broken Google Maps iframe embed

If all you need is a pin on your address, an iframe is the simplest map you can put on a page. It breaks for a small number of reasons: the wrong kind of URL in the src, a key problem on a Maps Embed API URL, or something on your site blocking the frame. Each has a quick fix.

How to tell this is your problem

  • The map area shows a grey box, a broken-page icon or the message that google.com refused to connect.
  • The iframe shows a Google error page instead of a map.
  • An embed that worked for years stopped after a site migration, a redesign or a security plugin change.
  • The src starts with https://maps.app.goo.gl/, https://goo.gl/maps/ or https://www.google.com/maps/place/.
  • You don't need markers you control, routes or search on the page. A single location is enough.

When the browser refuses to show a page inside a frame, the console shows something like this:

Refused to display 'https://www.google.com/' in a frame because it set 'X-Frame-Options' to 'sameorigin'.

Why it happens

Google Maps gives you several URLs for a place, and only some of them are meant to go inside an iframe.

URL starts withWhat it isWorks in an iframe?
maps.app.goo.gl/… or goo.gl/maps/…Short share link for people to clickNo
www.google.com/maps/place/…The full Google Maps websiteNo
www.google.com/maps/embed?pb=…Code from Share → Embed a mapYes, no key needed
www.google.com/maps/embed/v1/…?key=…Maps Embed APIYes, needs an API key

The Google Maps website refuses to load inside another site's frame, so a share link pasted into an iframe src shows an error or nothing. The two embed formats are built for framing. Of those, the Maps Embed API is Google's documented developer product, with parameters you control.

Other causes, in rough order of likelihood:

  • Key problems on an Embed API URL. The key is missing, deleted, restricted to other APIs, or its website restrictions don't include your domain.
  • Your Content-Security-Policy. A frame-src or child-src directive that doesn't allow https://www.google.com stops the frame loading at all. See the CSP directives Maps needs.
  • A consent or cookie tool that holds back third-party iframes until the visitor accepts.
  • Mangled HTML. A CMS field or editor converted & to & twice, stripped the iframe, or cut the pb= string short.
  • A zero-height wrapper. The iframe is fine but its container has no height. See fixing a zero-height map.

The fix, step by step

Option 1: the keyless share embed

  1. 01Open Google Maps, search for your business or address, and open the place.
  2. 02Click Share, then the Embed a map tab. Pick a size.
  3. 03Click Copy HTML and paste the whole <iframe> into your page in HTML or code mode, not the visual editor.

This is the quickest fix and needs no Cloud project. You get no control beyond the place and size, and the URL is an opaque pb= string you can't easily edit.

Option 2: the Maps Embed API

  1. 01In Google Cloud Console, enable the Maps Embed API on your project.
  2. 02Create an API key, or use your existing site key. Set its API restrictions to include the Maps Embed API and its website restrictions to your domains, for example https://example.com/* and https://www.example.com/*.
  3. 03Build the URL in the form https://www.google.com/maps/embed/v1/place?key=YOUR_KEY&q=…. The q parameter accepts a URL-escaped place name, address, plus code or Place ID.
  4. 04Replace the old iframe src. Keep the width and height, add loading="lazy" and give the frame a title for screen readers.
HTML
<iframe
  title="Map showing our office"
  width="600" height="450" style="border:0"
  loading="lazy" allowfullscreen
  referrerpolicy="strict-origin-when-cross-origin"
  src="https://www.google.com/maps/embed/v1/place?key=YOUR_API_KEY&q=Space+Needle,Seattle+WA">
</iframe>

Google's documentation states that all Maps Embed API requests are available at no charge with unlimited usage. You still need a key and a Cloud project. Besides place, the API has modes for view, directions, streetview and search.

Keep the referrer policy

Website restrictions on the key depend on the browser sending your site's address with the frame request. A referrerpolicy="no-referrer" on the iframe, or a site-wide Referrer-Policy: no-referrer header, stops that and the embed fails as if your domain weren't allowed. Google's own example uses strict-origin-when-cross-origin.

When an iframe isn't enough

Use the Maps JavaScript API instead if you need several markers from your own data, custom styling, clustering, a store locator or address search. If you already load the JavaScript API and see NotLoadingAPIFromGoogleMapsError, the script isn't coming straight from maps.googleapis.com. That is a different problem from a broken iframe; see fixing NotLoadingAPIFromGoogleMapsError.

On hosted platforms

Wix, Squarespace and Shopify each have their own map block, and most also accept a custom HTML or embed block where you can paste either iframe. If the platform block stopped working, an iframe in an embed block is a reliable fallback. See map blocks on Wix, Squarespace and Shopify.

Confirm it is fixed

Reload the page in a private window. The frame should show the map and the console should have no framing, CSP or Maps errors. Then scan the page. The scan lists Maps Embed API requests and any remaining Maps JavaScript API calls, so you can see whether an old plugin is still loading a second map you'd forgotten about.

Common questions

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

Not for the iframe from Google Maps' Share → Embed a map dialog. You do need one for the Maps Embed API, the URLs that start with google.com/maps/embed/v1/.

Does the Maps Embed API cost anything?

Google's documentation says Maps Embed API requests are available at no charge with unlimited usage. The Maps JavaScript API is billed differently, so don't assume the same applies to a JavaScript map.

Why does my embed say google.com refused to connect?

The src points at the Google Maps website or a share link, which can't be shown inside another site. Replace it with the code from Share → Embed a map, or a Maps Embed API URL.

Can I put several pins on an embedded map?

Not with a single place embed. The Embed API's search mode shows several results for a query, but for your own list of locations you need the Maps JavaScript API.

Check whether this is your error

A scan tells you in about twelve seconds, from a clean session.

Related articles