Cómo mostrar el tráfico en tiempo real en un mapa - Amazon Location Service

Las traducciones son generadas a través de traducción automática. En caso de conflicto entre la traducción y la version original de inglés, prevalecerá la version en inglés.

Cómo mostrar el tráfico en tiempo real en un mapa

Con Amazon Location Service puedes añadir características de tráfico a tu mapa. Esto proporciona datos de tráfico en tiempo real para mostrar las condiciones actuales del tráfico, como la congestión vial actual, las obras y los incidentes, lo que le ayuda a elegir las rutas.

Crea un mapa con el tráfico en tiempo real

En este ejemplo se muestra cómo crear un mapa con datos de tráfico en tiempo real.

index.html
<!DOCTYPE html> <html lang="en"> <head> <title>Traffic Map</title> <meta charset='utf-8'> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel='stylesheet' href='https://unpkg.com/maplibre-gl@5.x/dist/maplibre-gl.css' /> <script src='https://unpkg.com/maplibre-gl@5.x/dist/maplibre-gl.js'></script> </head> <body style="margin: 0; padding: 0;"> <div id="map" style="width: 100%; height: 100vh;"></div> <script> const apiKey = "Add Your Api Key"; const mapStyle = "Standard"; const awsRegion = "us-east-1"; const map = new maplibregl.Map({ container: 'map', style: `https://maps.geo.${awsRegion}.amazonaws.com/v2/styles/${mapStyle}/descriptor?traffic=All&key=${apiKey}`, center: [-74.0060 ,40.7128], // New York City coordinates for traffic visibility zoom: 12, validateStyle: false, // Disable style validation for faster map load }); </script> </body> </html>
style.css
body { margin: 0; padding: 0; } #map { width: 100%; height: 100vh; }