Sfpackage
[General]

How to embed Google map in HTML step by step guide

Ivy Watson // // 6 min // [en]
How to embed Google map in HTML step by step guide

A clear, step-by-step guide to embedding Google Maps in HTML using Embed API and JavaScript, with practical tips.

Embedding Google Maps in HTML is a common need for websites, blogs, and business pages. You have a few straightforward options, depending on whether you want a simple map or a fully interactive map with custom markers and events. This guide walks you through step by step, from a quick iframe embed to a fully customized JavaScript-powered map.

VPN

Quick start options compared

OptionSetupKey limitationBest use caseAvailabilityNotes
Iframe embed (no API key)EasyLimited interactivitySimple map displayImmediateNo API key needed
Maps Embed API (official)EasyQuotas applyQuick map embedsHighOfficial API embed
JavaScript API (interactive)ModerateMore codeFull interactivityScales wellRequires API key

Compiled November 2026; check the provider's site for current details.

Quick start: embed with an iframe (no API key)

If you just need a simple map that shows a location, an iframe embed is the fastest route.

Steps

  • Go to Google Maps and locate the place you want to show.
  • Click the Share button, then choose Embed a map.
  • Pick the desired size (small, medium, large) and copy the HTML iframe snippet.
  • Paste the code into your HTML where you want the map to appear.

Pros and cons

  • Pros: No API key required, easy, quick.
  • Cons: Limited customization, no markers beyond the location, no event handling.
How to embed Google map in HTML step by step guide: Checklist

Using the Maps Embed API (official, no heavy coding)

For more control than a basic iframe but still minimal code, use the Maps Embed API. This approach uses a URL-based embed with optional parameters.

What you need

  • A Google Cloud project and an API key with Maps Embed API enabled.
  • Basic HTML page to place the map.

How to build the embed URL

Example iframe

Key considerations

  • API key security: restrict by HTTP referrers (domains) to prevent misuse.
  • Usage limits and pricing: Maps Embed API has quotas. Monitor usage in Google Cloud Console.
  • Responsiveness: use responsive containers to keep the map view on different devices.

Embedding options vs features

Feature / MethodIframe (no API key)Maps Embed APIMaps JavaScript APIMulti-location supportCustom markersInteractivity
Need API keynooptional/requiredyesyesyesyes
Interaction depthlimitedlimitedfullyesyesfull
Custom markersnoyes (limited)yesyesyesyes
Multiple locationsyes (same map)yesyesyesyesyes
Offline cachingnononononono
Pricing modelfree tierfree tierpay as you godependsdependsdepends

Compiled November 2026; check the provider's site for current details.

Embedding an interactive map with the Maps JavaScript API

If you want interactivity like custom markers, info windows, or events, the Maps JavaScript API is the right choice. This requires loading the API script with your API key and writing a bit of JavaScript. Get paid in crypto

Prerequisites

  • A Google Cloud project with the Maps JavaScript API enabled.
  • An API key with proper restrictions.
  • A basic HTML page to load the map into a container div.

Minimal setup

  1. Add a container in your HTML:
  2. Include the API script with your key:
  3. Create a JavaScript function to initialize the map:
    • function initMap { var map = new google.maps.Map(document.getElementById('map'), { center: {lat: 37.4221, lng: -122.0841}, zoom: 14 }); }
    • Note: Replace coordinates with your target location.

Adding markers and info Windows

  • var marker = new google.maps.Marker({ position: {lat: 37.4221, lng: -122.0841}, map: map, title: 'My Location' });
  • var infowindow = new google.maps.InfoWindow({ content: 'My Location
    Address or description' });
  • marker.addListener('click', function { infowindow.open(map, marker); });

A small, practical example (all in one)

  • HTML:
  • JavaScript:
  • function initMap { var map = new google.maps.Map(document.getElementById('map'), { center: {lat: 40.7484, lng: -73.9857}, zoom: 13 }); var marker = new google.maps.Marker({ position: {lat: 40.7484, lng: -73.9857}, map: map, title: 'Empire State Building' }); var info = new google.maps.InfoWindow({ content: 'Empire State Building
    New York, NY' }); marker.addListener('click', function { info.open(map, marker); }); }

Tables: compare iframe, Embed API, and JavaScript API

Method Key required Customization Interactivity Use case
iframe embed Optional (no key required) Low None beyond default map actions Simple location display on a page
Maps Embed API Required (key) Moderate via URL params Basic controls, some interactions Simple branded embeds with parameters
Maps JavaScript API Required (key) High (markers, events, styles) Full interactivity (clicks, draggables, custom overlays) Complex maps with custom features

Best practices for the JavaScript API

  • Restrict your API key to your domains to prevent unauthorized use.
  • Enable only the APIs you need (Maps JavaScript API, optionally Geocoding, Places).
  • Use loading strategies: defer and async to avoid blocking rendering.
  • Handle errors gracefully in code (e.g., if the API fails to load).

Handling multiple locations and custom markers

If you need to show a list of locations, you can loop through a data array to add markers and attach info windows.

Example data-driven approach

  • var locations = [ {name: 'Store A', lat: 34.0522, lng: -118.2437, info: 'Downtown LA store'}, {name: 'Store B', lat: 37.7749, lng: -122.4194, info: 'San Francisco store'} ];
  • locations.forEach(function(loc) { var m = new google.maps.Marker({ position: {lat: loc.lat, lng: loc.lng}, map: map, title: loc.name }); var iw = new google.maps.InfoWindow({ content: '' + loc.name + '
    ' + loc.info }); m.addListener('click', function { iw.open(map, m); }); });
How to embed Google map in HTML step by step guide: Key points

Checklist comparison (steps from scratch)

StepIframe pathEmbed API pathJS API pathNotesRequired keysQuick start confidence
Get map URLyesyesyesCopy URL or codenohigh
Copy embed codeyesyesnoPaste into HTMLnohigh
Add API keynoyesyesIf using API-basedyesmedium
Set map sizeyesyesyeswidth/heightnohigh
Configure markersnolimitedfullCustom markersyesmedium
Test in browseryesyesyesResolve errorsyeshigh

Compiled November 2026; check the provider's site for current details.

Checklist: steps to embed Google Maps in HTML from scratch

  • Decide on embed method: iframe for quick display or JavaScript API for interactivity.
  • Create or open your HTML page.
  • If using iframe:
  • Use the embed code from Google Maps, paste into your page.
  • If using Maps Embed API:
  • Create a Google Cloud project, enable Maps Embed API, obtain an API key.
  • Build the embed URL with required parameters and place it in an iframe tag.
  • If using Maps JavaScript API:
  • Create a Google Cloud project, enable Maps JavaScript API, obtain an API key.
  • Add a map container div, load the API script with your key, and write initialization code (center, zoom, markers).
  • test on multiple devices and screen sizes to ensure responsiveness.
  • Monitor usage in the Google Cloud Console and implement key restrictions.

Security and pricing notes

  • API key safety: restrict by HTTP referrers (websites) or by IP address if server-side usage.
  • Billing and quotas: Google Maps Platform has pricing changes. Always review current quotas and enable alerts.
  • Terms of service: ensure your use complies with Google Maps Platform Terms and Attribution requirements.

Final recommendation

If you need a quick map for a static location, start with the iframe method. It’s fast, simple, and requires no code beyond inserting a snippet. If you want interactivity, multiple markers, custom styles, or events, use the Maps JavaScript API with an API key, following best practices for security and performance. For many sites, a blend works well: embed a basic map for the location, and add a JavaScript-powered map component where users can explore nearby points of interest or get directions.

© Sfpackage 2026v.1