Free tools Windows power users keep installed
One-click scans. No signup required.
Use Google Maps Platform’s google.maps.marker.AdvancedMarkerElement for new marker code. Load the Maps JavaScript API and its marker library, create a map with a map ID, then create one marker for each location. jQuery is optional: it can wait for the page, select elements, or iterate your location data, but Google’s API creates and manages the map and marker objects.
What you need before writing the code
- A Google Cloud project with billing enabled.
- A Maps JavaScript API key (or an OAuth token) and the Maps JavaScript API enabled for that project.
- A map ID. Google’s
DEMO_MAP_IDis suitable for testing; create and use a map ID owned by your project in production. - A map container with an explicit height. Without a height, the map can exist in the DOM but remain invisible.
Maps Platform charges depend on the request type and SKU. Do not assume that every map load is free or rely on an old flat-price figure; check Google’s current billing documentation for your account and region.
Programmatic Advanced Markers: the current approach
This complete example keeps the marker work in ordinary JavaScript and uses jQuery only to run code after the document is ready and to iterate the application data.
HTML and CSS
<div id="map"></div>
<style>
#map {
height: 420px;
width: 100%;
}
</style>
JavaScript with a jQuery loop
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script>
const locations = [
{ title: "New York", position: { lat: 40.7128, lng: -74.0060 } },
{ title: "Chicago", position: { lat: 41.8781, lng: -87.6298 } },
{ title: "Los Angeles", position: { lat: 34.0522, lng: -118.2437 } }
];
async function initMap() {
const { Map } = await google.maps.importLibrary("maps");
const { AdvancedMarkerElement } =
await google.maps.importLibrary("marker");
const map = new Map(document.getElementById("map"), {
center: locations[0].position,
zoom: 4,
mapId: "DEMO_MAP_ID" // Replace with your project map ID in production.
});
const markers = [];
$.each(locations, function (_index, location) {
const marker = new AdvancedMarkerElement({
map,
position: location.position,
title: location.title
});
markers.push(marker);
});
// Keep `markers` if the application will update or remove markers later.
window.mapMarkers = markers;
}
$(function () {
initMap().catch(function (error) {
console.error("Google Maps failed to initialize", error);
});
});
</script>
The API calls are deliberately explicit: importLibrary("maps") supplies the map class and importLibrary("marker") supplies AdvancedMarkerElement. The jQuery $.each call only walks your data; it does not create a Google marker.
#1 Best Overall
Loading the Maps JavaScript API
Load the Maps JavaScript API using Google’s current loader configuration and your key, then call initMap. A typical script-tag configuration is:
<script async
src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&loading=async&callback=initMap">
</script>
If you use the callback form, define initMap on the global scope before the loader invokes it and do not also initialize the map from a separate jQuery-ready callback. Choose one startup path. The earlier example uses jQuery readiness; in that case, load the API without a callback and call initMap yourself after the API loader is available.
Updating and removing markers
Keep references to marker instances when locations can change. To remove an advanced marker, set its map property to null; setting its position to null is also supported.
Rank #2
function removeMarker(marker) {
marker.map = null;
}
function clearMarkers(markers) {
markers.forEach(function (marker) {
marker.map = null;
});
markers.length = 0;
}
To move an existing marker, assign a new position rather than creating a second marker:
Recommended Free Tools
marker.position = { lat: 39.7392, lng: -104.9903 };
AdvancedMarkerElement versus the web-component style
Google documents two current ways to use advanced markers. They produce the same kind of map marker but fit different application architectures.
| Approach | How markers are created | Best fit | Lifecycle considerations |
|---|---|---|---|
| Programmatic API | new AdvancedMarkerElement({ map, position, title }) |
Applications that fetch, filter, or update locations in JavaScript | Store marker references so updates and removal are deterministic |
| Web components | <gmp-map> containing <gmp-advanced-marker> elements |
Pages already organized around custom elements and declarative markup | Let the component/DOM lifecycle own creation and teardown; verify integration details for your framework |
Do not mix both styles for the same marker set unless you have a specific reason. In a component-based application, make sure markers are not duplicated when a view re-renders.
Declarative markup outline
<gmp-map center="40.7128,-74.0060" zoom="4" map-id="DEMO_MAP_ID">
<gmp-advanced-marker
position="40.7128,-74.0060"
title="New York">
</gmp-advanced-marker>
</gmp-map>
This style requires the Maps web-component library and its corresponding loader configuration. Use a project map ID rather than the demo ID when deploying.
Legacy google.maps.Marker code
Older tutorials commonly use new google.maps.Marker(...). Google deprecated google.maps.Marker on February 21, 2024, with Maps JavaScript API v3.56. Google says the class is not currently scheduled for discontinuation, but recommends AdvancedMarkerElement for new implementations. Existing code may continue to work, yet new projects should not start on the deprecated class.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →| Legacy marker | Advanced marker |
|---|---|
new google.maps.Marker({ map, position }) |
new AdvancedMarkerElement({ map, position }) |
| Does not require the advanced marker library or a map ID in the same way | Requires the marker library and a map ID |
| Deprecated as of API v3.56 (February 21, 2024) | Google’s recommended choice for new marker implementations |
Common failures and fixes
The map area is blank
- Give the map container a non-zero CSS height.
- Check the browser console for an invalid key, disabled API, billing, or referrer-restriction error.
- Confirm that the map is initialized only after the Maps loader has finished.
“AdvancedMarkerElement is undefined”
The marker library was not imported. Await google.maps.importLibrary("marker") and use the returned AdvancedMarkerElement class.
Rank #4
The marker is rejected or does not render
Advanced markers require a map ID. Use DEMO_MAP_ID while testing or a map ID from your own Cloud project in production.
Markers appear twice
Your startup code is running from both a loader callback and a jQuery-ready handler, or a component is rendering the same data repeatedly. Initialize once and clear or reuse the stored marker references before rebuilding the set.
Nothing happens after changing the data array
Changing your application data does not automatically change existing map objects. Iterate the new data, update existing marker positions where possible, create markers for new records, and set removed markers’ map properties to null.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsBest Value
Choosing jQuery or plain JavaScript
Use jQuery if the rest of the page already depends on it or if its iteration and event helpers simplify your application code. Use plain JavaScript when you do not otherwise need the dependency. Neither choice changes the Google Maps API requirements: the map ID, marker-library import, credentials, and marker lifecycle remain the same.
Frequently Asked Questions
Can I still use the old google.maps.Marker class?
Yes, Google says it is not currently scheduled for discontinuation, but it has been deprecated since February 21, 2024, and AdvancedMarkerElement is recommended for new code.
Is jQuery required for Google Maps markers?
No. jQuery can handle page readiness or data iteration, while the Maps JavaScript API creates the map and marker instances.
Why does an AdvancedMarkerElement need a map ID?
Google requires a map ID for advanced markers. DEMO_MAP_ID is available for testing; production deployments should use a map ID from your own project.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




