{"id":375,"date":"2025-04-15T17:16:37","date_gmt":"2025-04-15T23:16:37","guid":{"rendered":"https:\/\/elblogdelgps.com\/ind\/?p=375"},"modified":"2026-03-22T20:33:46","modified_gmt":"2026-03-23T02:33:46","slug":"3-visualizacion-en-mapa-con-leaflet-openlayers-o-google-maps-api","status":"publish","type":"post","link":"https:\/\/elblogdelgps.com\/ind\/2025\/04\/15\/3-visualizacion-en-mapa-con-leaflet-openlayers-o-google-maps-api\/","title":{"rendered":"3.-Visualizaci\u00f3n en mapa con Leaflet, OpenLayers o Google Maps API"},"content":{"rendered":"<p>Una vez que los datos de geolocalizaci\u00f3n est\u00e1n en tu base de datos, el siguiente paso es <strong>representarlos gr\u00e1ficamente<\/strong> en un mapa interactivo. Esto mejora la experiencia del usuario al mostrar rutas, ubicaciones en tiempo real y eventos cr\u00edticos.<\/p><hr class=\"wp-block-separator has-alpha-channel-opacity\"\/><h3 class=\"wp-block-heading\">Herramientas disponibles<\/h3><figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Herramienta<\/th><th>Ventajas principales<\/th><th>Licencia<\/th><\/tr><\/thead><tbody><tr><td><strong>Leaflet<\/strong><\/td><td>Ligero, f\u00e1cil de usar, compatible con OpenStreetMap<\/td><td>Open Source (MIT)<\/td><\/tr><tr><td><strong>OpenLayers<\/strong><\/td><td>Potente y flexible, soporta m\u00faltiples capas<\/td><td>Open Source (BSD)<\/td><\/tr><tr><td><strong>Google Maps API<\/strong><\/td><td>Interfaz muy pulida, alta calidad de mapas<\/td><td>Comercial (requiere API Key)<\/td><\/tr><\/tbody><\/table><\/figure><hr class=\"wp-block-separator has-alpha-channel-opacity\"\/><h3 class=\"wp-block-heading\">Ejemplo: Visualizaci\u00f3n con Leaflet.js<\/h3><pre class=\"wp-block-preformatted\"><code>&lt;!DOCTYPE html><br>&lt;html><br>&lt;head><br>  &lt;title>Mapa GPS&lt;\/title><br>  &lt;link rel=\"stylesheet\" href=\"https:\/\/unpkg.com\/leaflet\/dist\/leaflet.css\" \/><br>  &lt;script src=\"https:\/\/unpkg.com\/leaflet\/dist\/leaflet.js\">&lt;\/script><br>&lt;\/head><br>&lt;body><br>  &lt;div id=\"map\" style=\"height: 500px;\">&lt;\/div><br><br>  &lt;script><br>    const map = L.map('map').setView([21.1526, -101.7117], 13); \/\/ Centro inicial<br><br>    L.tileLayer('https:\/\/{s}.tile.openstreetmap.org\/{z}\/{x}\/{y}.png', {<br>      attribution: '\u00a9 OpenStreetMap contributors'<br>    }).addTo(map);<br><br>    \/\/ Punto GPS (latitud, longitud)<br>    const marcador = L.marker([21.1526, -101.7117]).addTo(map);<br>    marcador.bindPopup(\"Veh\u00edculo activo&lt;br>Velocidad: 65 km\/h\").openPopup();<br>  &lt;\/script><br>&lt;\/body><br>&lt;\/html><br><\/code><\/pre><hr class=\"wp-block-separator has-alpha-channel-opacity\"\/><h3 class=\"wp-block-heading\">Con Google Maps API<\/h3><pre class=\"wp-block-preformatted\"><code>&lt;script src=\"https:\/\/maps.googleapis.com\/maps\/api\/js?key=TU_API_KEY\">&lt;\/script><br>&lt;script><br>  function initMap() {<br>    const ubicacion = { lat: 21.1526, lng: -101.7117 };<br>    const map = new google.maps.Map(document.getElementById(\"map\"), {<br>      zoom: 14,<br>      center: ubicacion,<br>    });<br>    const marker = new google.maps.Marker({<br>      position: ubicacion,<br>      map: map,<br>      title: \"Veh\u00edculo en movimiento\",<br>    });<br>  }<br>&lt;\/script><br>&lt;body onload=\"initMap()\"><br>  &lt;div id=\"map\" style=\"height:500px;\">&lt;\/div><br>&lt;\/body><br><\/code><\/pre><hr class=\"wp-block-separator has-alpha-channel-opacity\"\/><h3 class=\"wp-block-heading\">Buenas pr\u00e1cticas<\/h3><ul class=\"wp-block-list\"><li><strong>Actualizar en tiempo real<\/strong> usando WebSocket o peticiones peri\u00f3dicas (AJAX, fetch).<\/li>\n\n<li>Usar <strong>\u00edconos personalizados<\/strong> seg\u00fan estado del veh\u00edculo (apagado, en movimiento, alerta).<\/li>\n\n<li>Mostrar <strong>informaci\u00f3n contextual<\/strong> en el marcador: velocidad, direcci\u00f3n, hora, eventos.<\/li>\n\n<li>Implementar <strong>filtros por unidad, fechas, eventos, zonas<\/strong> para an\u00e1lisis hist\u00f3rico.<\/li><\/ul>","protected":false},"excerpt":{"rendered":"<p>Una vez que los datos de geolocalizaci\u00f3n est\u00e1n en tu base de datos, el siguiente paso es representarlos gr\u00e1ficamente en un mapa interactivo. Esto mejora la experiencia del usuario al mostrar rutas, ubicaciones en tiempo real y eventos cr\u00edticos. Herramientas disponibles Herramienta Ventajas principales Licencia Leaflet Ligero, f\u00e1cil de usar, compatible con OpenStreetMap Open Source [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":378,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"pagelayer_contact_templates":[],"_pagelayer_content":"","footnotes":""},"categories":[65],"tags":[68],"class_list":["post-375","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cursos-generales-modulo6","tag-capacitacion"],"_links":{"self":[{"href":"https:\/\/elblogdelgps.com\/ind\/wp-json\/wp\/v2\/posts\/375","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/elblogdelgps.com\/ind\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/elblogdelgps.com\/ind\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/elblogdelgps.com\/ind\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/elblogdelgps.com\/ind\/wp-json\/wp\/v2\/comments?post=375"}],"version-history":[{"count":2,"href":"https:\/\/elblogdelgps.com\/ind\/wp-json\/wp\/v2\/posts\/375\/revisions"}],"predecessor-version":[{"id":423,"href":"https:\/\/elblogdelgps.com\/ind\/wp-json\/wp\/v2\/posts\/375\/revisions\/423"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/elblogdelgps.com\/ind\/wp-json\/wp\/v2\/media\/378"}],"wp:attachment":[{"href":"https:\/\/elblogdelgps.com\/ind\/wp-json\/wp\/v2\/media?parent=375"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/elblogdelgps.com\/ind\/wp-json\/wp\/v2\/categories?post=375"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/elblogdelgps.com\/ind\/wp-json\/wp\/v2\/tags?post=375"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}