Skip to content

Commit

Permalink
feat: map user geolocation (#223)
Browse files Browse the repository at this point in the history
This pull request introduces a new feature to the
`app/src/app/Views/Admin/Inventory.php` file, which enhances the user
experience by utilizing the user's geolocation to interact with the map.

Geolocation feature:

* Added code to obtain the user's current position using the
`navigator.geolocation.getCurrentPosition` method, and create a marker
on the map at the user's location.
* Included functionality to center the map on the user's location and
adjust the zoom level for better visibility.
* Implemented error handling to log any issues encountered while
obtaining the user's location.
* Configured geolocation options for higher accuracy, a timeout limit,
and to always use fresh data.
  • Loading branch information
0x1026 authored Dec 18, 2024
2 parents db0bc96 + 10fba9c commit 9c4f9b7
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions app/src/app/Views/Admin/Inventory.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,32 @@ function spinGlobe() {

spinGlobe();

// Location User
navigator.geolocation.getCurrentPosition(
(position) => {
const { latitude, longitude } = position.coords;

// Crear un marcador exacto en la posición del usuario
new mapboxgl.Marker()
.setLngLat([longitude, latitude])
.addTo(map);

// Centrar el mapa en la ubicación del usuario
map.flyTo({
center: [longitude, latitude],
zoom: 15, // Ajusta el nivel de zoom si es necesario
essential: true // Garantiza la animación
});
},
(error) => {
console.error('Error al obtener la ubicación:', error);
},
{
enableHighAccuracy: true, // GPS más preciso
timeout: 10000, // Tiempo máximo para obtener la ubicación (ms)
maximumAge: 0 // Siempre obtener datos frescos
}
);
//GeoJSON
map.on('load', () => {
// Agregar fuente con GeoJSON
Expand Down

0 comments on commit 9c4f9b7

Please sign in to comment.