Timezones by point
Dieses Timezone-API-Beispiel zeigt, wie Sie Echtzeit-Zeitzoneninformationen in eine interaktive Karte mit SmartMaps GL integrieren. Wenn ein Nutzer auf einen beliebigen Punkt der Karte klickt, ruft die Anwendung die aktuelle Zeitzone, die Ortszeit und den UTC-Offset für diesen bestimmten Ort ab und zeigt sie an, wodurch sofortiger Zugriff auf präzise zeitbezogene Daten für jeden interessierenden geografischen Punkt möglich ist.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://cdn.smartmaps.cloud/packages/smartmaps/smartmaps-gl/v2/umd/smartmaps-gl.min.js"></script>
<style>
body {
margin: 0;
padding: 0;
}
html,
body,
#map {
height: 100%;
}
#controls {
position: absolute;
top: 10px;
left: 10px;
background: white;
padding: 10px;
z-index: 1;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
const apiKey = '[INSERT API-KEY]';
const map = new smartmapsgl.Map({
apiKey,
container: "map",
center: { lat: 49.02164948779226, lng: 8.439330018049352 },
zoom: 4,
style: smartmapsgl.MapStyle.AUTO
});
map.on('load', () => {
map.on('click', (e) => {
const latitude = e.lngLat.lat;
const longitude = e.lngLat.lng;
const url = `https://timezone.smartmaps.cloud/api/v1/timezone/current/point?IsoLocale=en-GB&Longitude=${longitude}&Latitude=${latitude}&ApiKey=${smartmapsgl.encodeString(apiKey)}&Details=SUN`;
fetch(url)
.then(response => response.json())
.then(data => {
const timezoneInfo = data.features[0].properties;
const popupContent = `
<strong>Timezone Information:</strong><br>
Timezone: ${timezoneInfo.timezone}<br>
Current Time: ${timezoneInfo.isoDateTimeText}<br>
UTC Offset: ${timezoneInfo.utcOffset}<br>
Timezone ID: ${timezoneInfo.timezoneId}<br>
Daylight Saving: ${timezoneInfo.isDaylight ? 'Yes' : 'No'}<br>
Sunrise: ${new Date(timezoneInfo.isoSunrise).toLocaleTimeString()}<br>
Sunset: ${new Date(timezoneInfo.isoSunset).toLocaleTimeString()}<br>
`;
new smartmapsgl.Popup()
.setLngLat(e.lngLat)
.setHTML(popupContent)
.addTo(map);
})
});
});
</script>
</body>
</html>