Skip to content

Instantly share code, notes, and snippets.

@gaetangr
Created May 30, 2025 13:54
Show Gist options
  • Save gaetangr/7e14fe153fec9f5dd5b1d867e25c2b2d to your computer and use it in GitHub Desktop.
Save gaetangr/7e14fe153fec9f5dd5b1d867e25c2b2d to your computer and use it in GitHub Desktop.
Marker Animation (Google Map)
<!DOCTYPE html>
<html>
<head>
<title>Carte Clients Front Desk</title>
<style>
#map {
height: 100vh;
width: 100%;
}
</style>
<script
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB41DRUbKWJHPxaFjMAwdrzWzbVKartNGg&callback=initMap&v=weekly"
defer></script>
<script>
const locations = [
{ lat: 48.8837, lng: 2.2097, name: "Nanterre" },
// Your cities here ...
];
function initMap() {
let sumLat = 0;
let sumLng = 0;
locations.forEach(loc => {
sumLat += loc.lat;
sumLng += loc.lng;
});
const center = {
lat: sumLat / locations.length,
lng: sumLng / locations.length
};
const map = new google.maps.Map(document.getElementById("map"), {
zoom: 5,
center: center
});
locations.forEach((loc, index) => {
setTimeout(() => {
const marker = new google.maps.Marker({
position: { lat: loc.lat, lng: loc.lng },
map: map,
title: loc.name,
animation: google.maps.Animation.DROP
});
const infowindow = new google.maps.InfoWindow({
content: `<strong>${loc.name}</strong><br>Lat: ${loc.lat.toFixed(5)}<br>Lng: ${loc.lng.toFixed(5)}`
});
marker.addListener("click", () => {
infowindow.open(map, marker);
});
}, index * 200);
});
}
</script>
</head>
<body>
<div id="map"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment