How to Capture a Google Map with JavaScript or jQuery
Choose the documented Google Maps API for a static image or an interactive map, with runnable JavaScript, jQuery, cURL, Python and Node.js examples.

Short answer: “Capture” can mean two different things. If you need a PNG, JPEG or GIF, use the documented Google Maps Static API. If you need a draggable, zoomable map, use the Maps JavaScript API. jQuery can build a Static API URL or insert the resulting image, but jQuery is not a map-export service.
An arbitrary screenshot of a rendered Maps JavaScript map is not the documented Google export route. It can also run into browser-origin restrictions and Google policy limits. Use the Static API for a still image, and keep the JavaScript API map interactive when that is the actual requirement.
1. Choose the right capture method
| Requirement | Use | What you receive |
|---|---|---|
| Fixed map image for a report, card or email | Maps Static API | PNG, JPEG or GIF from an HTTPS URL |
| Dragging, zooming, controls or live data | Maps JavaScript API | An interactive map in the page |
| Server-side Google Apps Script | Maps.newStaticMap() |
A URL, blob or image bytes |
| Automated screenshot of a page that contains a map | A browser automation tool or ScreenshotNeo | A page screenshot, subject to the page and provider’s policies |
For a static image, create a Google Cloud project, enable Maps Static API, create an API key, restrict that key appropriately and enable billing. Google documents center and zoom when markers do not establish the view, and size is required. Put the request behind HTTPS on an HTTPS site and URL-encode values.
2. Get a static map image with JavaScript
This browser example builds a URL and assigns it to an image element. Replace the placeholder key with a restricted key supplied by your Google Cloud project.

<img id="map-image" width="600" height="400" alt="Map centered on San Francisco">
<script>
const params = new URLSearchParams({
center: 'San Francisco, CA',
zoom: '12',
size: '600x400',
maptype: 'roadmap',
format: 'png',
scale: '1',
key: 'YOUR_API_KEY'
});
document.querySelector('#map-image').src =
`https://maps.googleapis.com/maps/api/staticmap?${params}`;
</script>
The same request can be made with fetch when you need to inspect the response or save it:
const params = new URLSearchParams({
center: 'San Francisco, CA',
zoom: '12',
size: '600x400',
key: 'YOUR_API_KEY'
});
const response = await fetch(
`https://maps.googleapis.com/maps/api/staticmap?${params}`
);
if (!response.ok) throw new Error(`Map request failed: ${response.status}`);
const imageBytes = await response.arrayBuffer();
// Store imageBytes in your application or create a Blob for download.
Markers, paths and styles
Static API parameters control the view. For example, add a marker and a route line:
const params = new URLSearchParams({
center: '40.7128,-74.0060',
zoom: '12',
size: '640x640',
markers: 'color:red|40.7128,-74.0060',
path: 'color:0x0000ff|weight:5|40.7128,-74.0060|40.7306,-73.9866',
maptype: 'roadmap',
key: 'YOUR_API_KEY'
});
const url = `https://maps.googleapis.com/maps/api/staticmap?${params}`;
Use roadmap, satellite, terrain or hybrid. Formats include PNG, JPEG and GIF. Google describes JPEG as lossy and PNG/GIF as lossless, so choose based on the output rather than treating format as a resolution setting.
3. The same Static API request with cURL, Python and Node.js
cURL
curl -G "https://maps.googleapis.com/maps/api/staticmap" \
--data-urlencode "center=San Francisco, CA" \
--data-urlencode "zoom=12" \
--data-urlencode "size=600x400" \
--data-urlencode "format=png" \
--data-urlencode "key=YOUR_API_KEY" \
-o map.png
Python
import requests
params = {
"center": "San Francisco, CA",
"zoom": 12,
"size": "600x400",
"format": "png",
"key": "YOUR_API_KEY",
}
response = requests.get(
"https://maps.googleapis.com/maps/api/staticmap",
params=params,
timeout=30,
)
response.raise_for_status()
with open("map.png", "wb") as output:
output.write(response.content)
Node.js
const params = new URLSearchParams({
center: 'San Francisco, CA',
zoom: '12',
size: '600x400',
format: 'png',
key: 'YOUR_API_KEY'
});
const response = await fetch(
`https://maps.googleapis.com/maps/api/staticmap?${params}`
);
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const buffer = Buffer.from(await response.arrayBuffer());
await import('node:fs/promises').then(fs => fs.writeFile('map.png', buffer));
4. Build the URL with jQuery
jQuery is useful for assembling a request and placing the returned image in the DOM. Use encodeURIComponent for each value, or use URLSearchParams in modern browsers.
const query = $.param({
center: 'San Francisco, CA',
zoom: 12,
size: '600x400',
maptype: 'roadmap',
key: 'YOUR_API_KEY'
});
$('#map-image')
.attr('src', `https://maps.googleapis.com/maps/api/staticmap?${query}`)
.attr('alt', 'Map centered on San Francisco');
Do not expose an unrestricted key in a public page. Apply HTTP referrer restrictions for browser use, or keep the request on your server when a server-side credential is more appropriate.
5. Capture an interactive map with the Maps JavaScript API
Use this route when the user must pan, zoom, inspect markers or interact with controls. Google’s current guide also recommends considering the declarative gmp-map web component for new projects; the established div plus JavaScript approach remains supported.
<div id="map" style="height:400px"></div>
<script>
async function initMap() {
const { Map } = await google.maps.importLibrary('maps');
new Map(document.getElementById('map'), {
center: { lat: 37.7749, lng: -122.4194 },
zoom: 12,
mapTypeId: 'roadmap'
});
}
</script>
<script async src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap"></script>
Keep Google Maps attribution visible and follow the current Maps JavaScript API policies. Google restricts pre-fetching, caching and storage in general, with place IDs treated separately. Persisting a place name for use outside the user’s session can constitute scraping. Service terms and requirements can vary, including for EEA use, so review the current policies before storing or redistributing map content.
6. Static map dimensions, scale and zoom
- At
scale=1, the documented default ceiling is 640×640 pixels. scale=2keeps the same geographic coverage but returns twice the pixels in each dimension, up to 1280×1280.- Larger requests require contacting Google support; the stated support-reviewed maximum is 2048×2048.
- Static API URLs are limited to 16,384 characters, so long marker and path lists may need to be simplified.
- Approximate zoom levels are 1 for world, 5 for continent, 10 for city, 15 for streets and 20 for buildings. Detail and availability vary by location.
A requested zoom can produce a blank image when tiles are unavailable in that location. Treat a blank response as a location and zoom problem first, not as proof that the request code is invalid.
7. Google Apps Script option
For Apps Script, Google provides Maps.newStaticMap() and the StaticMap class. It can set the size, center, markers, paths, format and map type. getMapUrl() returns a URL, while getBlob() or getMapImage() returns image data.
function createMapBlob() {
const map = Maps.newStaticMap()
.setCenter('San Francisco, CA')
.setZoom(12)
.setSize(600, 400)
.setMapType(Maps.StaticMap.Type.ROADMAP)
.addMarker(37.7749, -122.4194);
// Use the URL in a document or return image bytes to another service.
const url = map.getMapUrl();
const blob = map.getBlob();
return { url, blob };
}
Google says static map URLs require an API key. Configure credentials and billing for the project according to the current Google documentation.
8. Or skip the browser setup
If your real goal is an automated screenshot of a map page, ScreenshotNeo makes one GET request and returns a PNG, JPEG, WebP or PDF. It can capture the rendered page or one element by CSS selector, wait for a selector, delay or network idle, run custom JavaScript, set a viewport or device preset, and hide unwanted selectors.

Cookie and consent banners are accepted and removed before capture, along with more than 60 known consent platforms, newsletter popups and chat widgets. Bot checks, blank pages, timeouts, failed loads and cache hits are not billed, and the response identifies the result with X-Page-Verdict and X-Billed headers. Its MCP server gives Claude, Cursor and other MCP clients take_screenshot, get_page_info and capture_pdf tools.
See the ScreenshotNeo API documentation for all options.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' }); const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
There are 1,000 free screenshots each month with no card; paid plans start at $5 for 3,000. Create a free ScreenshotNeo account.
9. Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| “This page can’t load Google Maps correctly” | Missing, invalid or restricted key; API or billing not enabled | Check the project, enable Maps Static or JavaScript API, verify restrictions and billing. |
| Blank static image | Tiles are unavailable at the requested zoom or location | Try a lower zoom, a nearby center or a supported map type. |
| Image is too small | size and scale describe output limits |
Use up to 640×640 at scale 1, or scale 2 for up to 1280×1280 pixels. |
| Request rejected or truncated | URL exceeds 16,384 characters | Reduce markers, simplify paths and shorten encoded style parameters. |
| jQuery image never appears | Malformed query string, blocked key or mixed content | Inspect the final URL, use HTTPS, check the network response and verify key restrictions. |
| Interactive map does not initialize | Callback runs before code exists or the API key is invalid | Define the callback first, inspect the browser console and confirm the Maps JavaScript API is enabled. |
| Screenshot includes a cookie banner or chat bubble | A browser screenshot captured the page before cleanup | Dismiss or hide those elements before capture, or use ScreenshotNeo’s consent and widget removal. |
10. Performance, reliability and cost
- Use a static image when interaction is unnecessary; it avoids loading a full map application in every viewer’s browser.
- Choose the smallest dimensions and scale that meet the display requirement.
- Cache only where Google’s current terms allow it. Do not assume that a screenshot grants permission to store or scrape map content.
- Keep API keys restricted and monitor the Google Cloud project because Static API and JavaScript API require billing-enabled projects.
- Handle non-200 responses, blank images and quota failures explicitly. Retry transient network failures with backoff rather than retrying every API error.
- For automated page screenshots, set a deterministic viewport, wait for the map and lazy content, and use a cache when repeated captures are acceptable.
11. FAQ
Can I save a Google JavaScript map as a PNG with jQuery?
jQuery does not provide a supported map export. Use Maps Static API for a documented image response, or keep the JavaScript API map interactive.
Should I use Static API or JavaScript API for a locator?
Use JavaScript API when visitors need to pan, zoom or interact. Use Static API for fixed thumbnails, printed documents and emails.
Can I request a 4K static map?
The documented default limit is 640×640, with scale 2 returning up to 1280×1280. Larger sizes require Google support review and have a stated maximum of 2048×2048.
Why does a higher zoom show no map?
Some locations do not have tiles at every zoom. Lower the zoom or adjust the center.
Is a Google Maps screenshot automatically free to reuse?
No. Attribution, caching, storage and scraping rules still apply. Read the current Maps JavaScript API policies and the terms applicable to your project.


