I'm trying to migrate my custom map markers to the new advanced marker library, seems the animation options is no more available, it give me this error:
Unknown property 'animation' of AdvancedMarkerElement
I checked the documentation and the animation options is still there but nothing is mentioned about how to migrate the animation option.
newMarker = new google.maps.marker.AdvancedMarkerElement({
position: markerOpposto,
map: map,
content: imageIcon,
title: "New position",
animation: google.maps.Animation.BOUNCE
})
Use CSS animation for Advanced Markers
First thing that we need to understand about Advanced Marker is that it is no longer an MVC Object unlike the Legacy Markers. The
Animation constants(BOUNCEandDROP) that existed on the Legacy Marker are no longer available.That is because, as per the documentation, the Advanced Marker class now extends
HTMLElement. This means that to animate the Advanced Marker, you should use CSS animation now to be able to do so as presented in their Advanced Marker sample here: https://developers.google.com/maps/documentation/javascript/examples/advanced-markers-animationWith that said, to reproduce a somewhat similar bounce animation, you first need to define a
.bounce(You can name this whatever you want) class inside your CSS using keyframes and transform:Then inside your map initialization function, you can just add the class
.bounceto your marker element by using this code:Then the animation should work.
Here's a proof of concept snippet for you to check: