Google Maps Add-on: Supporting Advanced Markers

A few weeks ago, we released version 2.7.0 of the FlowingCode Google Maps Add-on, which added support for Advanced Markers. Now we want to tell you how we got there.
It all started with a deprecation warning that began showing up in the console for users of our add-on. On February 21, 2024, Google officially deprecated the classic google.maps.Marker API in favor of the new google.maps.marker.AdvancedMarkerElement. The classic markers still work fine, and Google says they are not scheduled to be discontinued. Even so, it was time to support the modern standard.
Getting there was harder than it looked. Advanced Markers are not a drop-in replacement, and we went through a few rounds of testing and redesign before landing on the right approach. This article is a behind-the-scenes look at the result: the design decisions, how we got feature parity with the classic marker, and how we delivered it in small, reviewable steps.
Why Not Just Replace the Classic Marker?
The official migration guide makes it look like a simple swap. It isn’t. Advanced Markers use a different architecture:
- They require the map to have a
mapId; without it, they don’t render. And once a map has amapId, itsstylesproperty no longer applies: styling moves to the Google Cloud console. - They drop the classic setter methods (
setIcon(),setPosition(),setMap()) in favor of direct property assignment. - Styling is done with DOM elements (
PinElementor custom HTML content) instead of raster icons,Symbolpaths andMarkerLabel. - Only
clickis fired as a Maps API event. Double click, right click and themouse*events are gone.
Replacing google-map-marker would have broken both the web component API and the Java API (GoogleMapMarker#setIcon and friends), and would have forced every existing map to define a mapId. That means a major version and a painful upgrade for everyone, just to get rid of a warning that comes from Google, not from us.
There was also no rush. Deprecated doesn’t mean removed: according to Google’s deprecations page, google.maps.Marker is not scheduled to be discontinued, and at least 12 months’ notice will be given before support ends. With no removal date in sight, forcing everyone to migrate now made no sense. Keeping both markers does.
So we went with coexistence: google-map-marker stays exactly as it is, and a new google-map-advanced-marker element sits next to it in our Google Maps web component. Both can be used on the same map, so you can migrate one marker at a time.
The Goal: Feature Parity, Not “Mostly Works”
The easy path would have been to support only what Advanced Markers do natively (pin colors, glyphs, custom content) and declare everything else unsupported. We set a stricter goal: everything you can do with the classic marker should be possible with the advanced one. Where there is no native equivalent, we emulate it. If emulation doesn’t make sense, we document it.
The new element keeps the same contract as google-map-marker: same attributes, same google-map-marker-* events with the same event details, same InfoWindow behavior and the same click-events, drag-events and mouse-events switches. Some highlights:
- Icons.
iconaccepts the same values as before. An image URL or anIconobject becomes an<img>used as the marker content, honoringscaledSizeandanchor. ASymbolwith an SVGpathis rendered as an inline<svg>with the same defaults asgoogle.maps.Symbol(fill, stroke, scale, rotation, anchor). - Labels.
label(a string or aMarkerLabel) is rendered as the glyph text of the default pin, in the label’s color. - Events.
dblclick,rightclickand themouse*events are taken from DOM listeners on the marker and re-fired with the samelatLnganddomEventdetail as the classic marker. Touch-and-hold on mobile firesrightclick, as it does for the classic marker. - Visibility and dragging. The native
hidden,titleanddraggableattributes work as they do on the classic element.
A few things have no meaningful equivalent and are documented as not supported: animation, optimized, google.maps.SymbolPath constants, icon sprites (size and origin), label together with icon, and the label’s font and CSS class.
Using It from Vaadin
On the Java side, the new marker is GoogleMapAdvancedMarker. It reuses the types you already know (LatLon, MarkerIcon, Symbol, MarkerLabel), so moving a marker over is mostly a matter of changing the class name:
GoogleMap gmaps = new GoogleMap(apiKey, null, null);
// Advanced Markers require a Map ID. "DEMO_MAP_ID" can be used for testing.
gmaps.setMapId("DEMO_MAP_ID");
// A marker with a customized pin and an info window
GoogleMapAdvancedMarker office =
new GoogleMapAdvancedMarker("Flowing Code", new LatLon(-31.636036, -60.7055271), false);
office.setPinBackground("#1a73e8");
office.setPinBorderColor("#0b4f9c");
office.setPinGlyphColor("white");
office.addInfoWindow("<b>Flowing Code</b>");
gmaps.addMarker(office);
// A marker with a label that handles clicks and right clicks (touch-and-hold on touch devices)
GoogleMapAdvancedMarker labeled =
new GoogleMapAdvancedMarker("Label", new LatLon(-31.6400, -60.6960), false);
MarkerLabel label = new MarkerLabel("1");
label.setColor("white");
labeled.setLabel(label);
labeled.addClickListener(e -> Notification.show("Clicked"));
labeled.addRightClickListener(e -> Notification.show("Right clicked"));
gmaps.addMarker(labeled);
// Classic markers keep working on the same map
gmaps.addMarker(new GoogleMapMarker("Classic marker", new LatLon(-31.6310, -60.7150), false));Clustering works the same way as with classic markers: call gmaps.enableMarkersClustering() and the advanced markers are grouped too. The add-on demo includes two new examples, Advanced Markers and Advanced Markers Clustering.

Two design decisions are worth mentioning:
- A separate class, not a subclass.
GoogleMapAdvancedMarkerdoesn’t extendGoogleMapMarker. If it did, it would inherit methods likesetAnimation()orsetOptimized()that can’t work, and the best we could do is throw at runtime. As a separate class, those methods simply don’t exist, so the compiler tells you what isn’t supported. In exchange, it adds what only Advanced Markers have, likesetPinBackground(),setPinBorderColor(),setPinGlyphColor()andsetPinScale(). And some things work better than before:setVisible(false)hides an advanced marker at any time, while on a classic marker it has no effect once the marker is created. - Fail early without a Map ID. In the browser, an Advanced Marker on a map without a Map ID just doesn’t show up, with no error, and the Map ID can’t be changed once the map is created. Rather than leaving you to wonder where your markers went, an advanced marker on a map without a Map ID throws an
IllegalStateExceptionthat says what is missing, as soon as the marker is added to a map that is already shown, or when the map is shown.
Lessons from the Implementation
Load the library once, up front
The obvious way to get the marker library is to load it on demand with await google.maps.importLibrary('marker'). But that makes the advanced marker asynchronous while the classic one is synchronous, and it leads to race conditions: MarkerClusterer, for example, can call setMap() before the AdvancedMarkerElement exists. You can work around it by queuing calls until the marker is ready, but that spreads timing workarounds everywhere.
Instead, we fixed it at the source. Our shared API loader (@flowingcode/google-apis) now requests the marker library together with the others, so google.maps.marker is available as soon as the map is ready. The advanced marker is built synchronously, just like the classic one, with no workarounds needed. While we were there, we also removed the drawing and visualization libraries, which Google has retired.
Speak the clusterer’s language
MarkerClusterer handles markers through a small duck-typed API: getPosition(), setMap(), getVisible(). The new element exposes the same methods as google-map-marker, so clustering works with both marker types, even mixed on the same map.
Loading the marker library had a side effect we didn’t see coming, though. Recent versions of @googlemaps/markerclusterer draw the cluster icons themselves as Advanced Markers whenever the Maps API reports them as available, and with the library loaded, it does, even on maps without a Map ID. On those maps, the cluster icons can’t be shown, and the map displays Google’s “This page can’t load Google Maps correctly” error. Since this hit the classic markers, which were supposed to stay untouched, it had to be fixed before releasing: on maps without a Map ID, google-map now tells the clusterer to draw its icons with the classic marker, as before. Maps with a Map ID get the new cluster icons, and custom renderers are used as they are.
One detail was easy to miss: the clusterer hides grouped markers by setting their map to null. If we also used map to implement hidden, a marker leaving a cluster could reappear even though it was hidden. So hidden is applied through CSS on the marker content, and map stays under the clusterer’s control.
Keep the event detail stable
Google recommends the new gmp-click DOM event for Advanced Markers, but it doesn’t carry latLng or domEvent, which are part of the event detail our users (and our Java API) already rely on. We kept the Maps API listener for click and built the detail ourselves for the DOM events, so the same listener works for both markers.
Touch-and-hold is harder than it looks
Touch devices have no right click, so the classic marker already turns a long press into a rightclick event (we covered it in Mobile Right-Click for Markers). The advanced marker had to do the same, this time with pointer events: a press that lasts 800 ms fires rightclick, and the click that comes right after it is swallowed, so the InfoWindow doesn’t open too.
The basic version is short. The edge cases took more work:
- Moving the finger away. The natural way to cancel the long press is
pointerleave. But on touch devices the pointer is implicitly captured by the element where the touch started, sopointerleaveonly arrives when the finger is lifted. If the user started panning the map from a marker, the long press fired anyway. Checking the marker bounds didn’t help either: a marker with an icon has a zero-size content box, with the image positioned around it. The solution was a movement threshold: if the finger moves more than 10 px from where it started, it’s not a long press. - The browser gets there first. Some platforms, like Android, fire their own
contextmenuduring a long press, before our timer. That becomes therightclickand cancels our timer, but the click that follows must still be swallowed. - Not swallowing too much. The flag that swallows the click must also expire. Some platforms don’t send a click after a long press, and then a later click, or a keyboard activation, would be swallowed by mistake.
- Leaving nothing behind. A pending long press is cancelled if click events are turned off or the marker is removed, and mouse pointers (for example on touchscreen laptops) are ignored, since they have a real right click.
None of this is visible when it works, which is the point: a long press on an advanced marker behaves just like one on a classic marker.
Map IDs and custom styles
Requiring a Map ID has a side effect. With the classic setup, you can customize the look of the map from code, passing a list of style rules (styles) like “gray roads” or “hide points of interest”. But when a map has a Map ID, Google takes its style from the configuration of that Map ID in the Google Cloud console instead, ignores styles, and logs a warning in the browser console.
So if you style your map from code and want to switch to Advanced Markers, you’ll need to recreate that style in the Cloud console. On our side, google-map no longer passes styles to Google when a Map ID is set, which avoids the warning, and the documentation of mapId explains this trade-off.
Small Pull Requests, Easier Reviews
A feature this size is hard to review in one piece: every review round tends to reopen discussions about unrelated parts. So we posted the design decision on the issue first and then split the work into a stack of small pull requests, each reviewable on its own:
- API loader: drop the retired libraries and load the
markerlibrary. - Core element: position, pin customization, click and drag events, InfoWindow,
fit-to-markers, clustering, and the demos. - Events: double click, right click, touch-and-hold and mouse events.
- Appearance: icon and label.
- Java wrapper:
GoogleMapAdvancedMarkerin the Vaadin add-on.
To avoid regressions, we checked each step against the current release. We ran the same checks on master and on the branch, with classic and advanced markers side by side, and compared the results. This also surfaced a few existing bugs in the shared map code, which we are tracking separately instead of mixing them into this feature.
Testing the Java API before releasing the web component
The Java wrapper depends on the web component through npm, so normally it can only use a published version. But we wanted to build the Java side first: if it revealed something missing in the web component, we could fix it before releasing, instead of publishing a patch right after.
The trick was a local package. Running npm pack in the web component repository creates a .tgz archive of the working tree, exactly as it would be published. Then, in the Vaadin add-on, we temporarily pointed the dependency to that file with the file: protocol in package.json. Vaadin installs it like any other package, so we could test the whole chain, from the Java API down to the AdvancedMarkerElement in the browser, without publishing anything. Once everything worked, the web component was released once, and the add-on was switched back to the published version.
Wrapping Up
At FlowingCode, our priority is giving Vaadin developers access to the latest web capabilities without compromising the stability of their existing applications.
Advanced Markers arrive as an opt-in element that works like the marker you already know: same attributes, same events, same clustering, with icons, labels and mouse events emulated where Google dropped them. Your existing maps keep working untouched, and you can migrate at your own pace, one marker at a time.
Advanced Markers are available in the FlowingCode Google Maps Add-on since version 2.7.0. Check out the API and start experimenting with it in your projects!
Be sure to explore everything else the Google Maps Add-on has to offer in our online demo. If you have ideas for enhancing this or any other part of the add-on, please let us know by opening an issue on the GitHub repository.
You can find more information about existing versions and supported Vaadin versions on Vaadin’s Directory.
Thanks for reading and let’s keep the code flowing!
Join the conversation!