Skip to main content

Overview

The Employee GPS Tracking feature enables real-time location monitoring of employees during their work shifts. Using browser-based geolocation APIs, the system automatically captures and records employee positions at regular intervals, providing administrators with accurate attendance data and location history.
This feature uses the HTML5 Geolocation API and requires users to grant location permissions in their browser.

How It Works

1

Employee Initiates Tracking

Employees log into the system and click the “Iniciar Turno” (Start Shift) button to begin location tracking for their work session.
2

Automatic Location Capture

The system captures GPS coordinates every 50 minutes automatically using the browser’s geolocation API.
3

Data Storage

Each location ping is stored with the employee’s username, coordinates, date, and timestamp in the system’s database.
4

Admin Monitoring

Administrators can view all location records in real-time through the admin dashboard.

User Workflow

For Employees

  1. Login: Access the system using credentials
  2. Start Tracking: Click the “Iniciar Turno” button on the homepage
  3. Grant Permissions: Allow browser location access when prompted
  4. Monitor Status: View the last update timestamp to confirm tracking is active
The tracking button is disabled once activated to prevent accidental duplicate sessions.

Employee Interface

The employee tracking interface is simple and user-friendly:
<div class="card">
    <h1>Hola, {{ usuario }}</h1>
    <p id="msg">Presiona para iniciar tu monitoreo de jornada.</p>
    <button id="btn-start" onclick="iniciarJornada()">Iniciar Turno</button>
    <hr>
    <p>Último reporte: <span id="last-update">-</span></p>
    <a href="/logout">Salir</a>
</div>

Technical Implementation

Geolocation API Usage

The system uses the HTML5 Geolocation API with high accuracy enabled:
function iniciarJornada() {
    document.getElementById('btn-start').disabled = true;
    document.getElementById('msg').innerText = "Rastreo activo (Cada 50 min)";
    enviarUbicacion();
    setInterval(enviarUbicacion, 50 * 60 * 1000); // 50 minutes
}

function enviarUbicacion() {
    navigator.geolocation.getCurrentPosition((pos) => {
        fetch('/update-location', {
            method: 'POST',
            headers: {'Content-Type': 'application/json'},
            body: JSON.stringify({ 
                lat: pos.coords.latitude, 
                lon: pos.coords.longitude 
            })
        });
        document.getElementById('last-update').innerText = new Date().toLocaleTimeString();
    }, (err) => alert("Activa el GPS"), { enableHighAccuracy: true });
}

50-Minute Interval Strategy

The 50-minute interval balances several key factors:
  • Battery efficiency: Reduces power consumption on mobile devices
  • Data volume: Minimizes storage requirements while maintaining adequate coverage
  • Network usage: Reduces bandwidth consumption for remote workers
  • Sufficient monitoring: Provides enough data points during an 8-hour shift (approximately 9-10 location captures)

Backend Processing

The Flask backend receives and stores location data in app.py:116-132:
@app.route('/update-location', methods=['POST'])
@login_required
def update_location():
    data = request.json
    registros = leer_json(REGISTROS_FILE)
    ahora = datetime.datetime.now()
    
    nuevo = {
        "usuario": current_user.id,
        "lat": data['lat'],
        "lon": data['lon'],
        "fecha": ahora.strftime("%Y-%m-%d"),
        "hora": ahora.strftime("%H:%M:%S")
    }
    registros.append(nuevo)
    guardar_json(REGISTROS_FILE, registros)
    return jsonify({"status": "OK"})

Data Structure

Location Record Format

Each GPS ping is stored with the following structure:
{
  "usuario": "empleado1",
  "lat": 19.432608,
  "lon": -99.133209,
  "fecha": "2026-03-05",
  "hora": "08:15:30"
}

usuario

The employee’s username identifier

lat / lon

Latitude and longitude coordinates in decimal degrees format

fecha

Date in YYYY-MM-DD format for easy sorting and filtering

hora

24-hour format timestamp (HH:MM:SS) used for tardiness detection

Privacy & Security

Important Privacy Considerations:
  • Location tracking only occurs during work hours when explicitly activated by the employee
  • GPS coordinates are stored securely on the server
  • Only administrators have access to view location data
  • Employees can see their last update timestamp but cannot access historical coordinates

Permission Requirements

Browsers require explicit user consent before accessing location data:
  • First-time users: Browser shows a permission prompt
  • Denied permissions: System displays “Activa el GPS” alert
  • High accuracy mode: Enabled for precise location capture

Troubleshooting

Common causes:
  • GPS/location services disabled in browser or device
  • No internet connection for data transmission
  • Browser doesn’t support Geolocation API (very rare)
Solutions:
  • Check browser location permissions
  • Ensure stable internet connectivity
  • Try a different browser (Chrome, Firefox, Safari recommended)
Common causes:
  • Poor GPS signal indoors or in dense urban areas
  • Device using WiFi-based location instead of GPS
  • High accuracy mode not enabled
Solutions:
  • Move to location with clear sky view
  • Enable high accuracy in device location settings
  • Wait for GPS lock before clicking “Iniciar Turno”

Integration with Other Features

The tracking system integrates seamlessly with:

Best Practices

For Administrators:
  • Clearly communicate tracking policies to employees
  • Define acceptable work locations if applicable
  • Regularly review location data for attendance patterns
For Employees:
  • Start tracking immediately upon beginning work
  • Keep device charged to ensure continuous tracking
  • Verify location permissions are granted
  • Monitor the “Último reporte” timestamp to confirm system is working

Build docs developers (and LLMs) love