Skip to content

A GPS speedometer PWA with analog/digital views, dark/light themes. No dependencies.

License

Notifications You must be signed in to change notification settings

mamdous-usual/speedometer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

2 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš— Speedometer

License PWA Vanilla JS No Dependencies

A high-performance Progressive Web App speedometer built with vanilla HTML, CSS, and modern JavaScript (ES6+). Track your speed in real-time using GPS with beautiful analog and digital displays.

๐ŸŒ Live Demo

๐Ÿ‘‰ View Live App

Try it out on your phone while walking or driving to see real-time speed tracking!

โœจ Features

  • ๐Ÿ“ Real-time GPS Tracking - Uses Browser Geolocation API with watchPosition and high accuracy mode
  • ๐ŸŽฏ Dual Speed Calculation - Uses native GPS speed or calculates from position using Haversine formula
  • ๐ŸŽจ Dual Display Modes - Switch between analog gauge and digital display
  • ๐ŸŒ“ Dark/Light Theme - OneDark theme with smooth transitions
  • โšก Smooth Animations - 60 FPS needle animation using requestAnimationFrame
  • ๐Ÿ“Š Speed Smoothing - Exponential Moving Average (EMA) to reduce GPS jitter
  • ๐Ÿ“ฑ PWA Support - Install on your device, works offline
  • ๐Ÿ”‹ Battery Efficient - Optimized for low power consumption
  • ๐Ÿ“ Responsive Design - Works on all screen sizes (mobile, tablet, desktop)
  • โ™ฟ Accessible - ARIA labels, keyboard navigation, reduced motion support

๐Ÿ› ๏ธ Tech Stack

Technology Purpose
HTML5 Semantic markup
CSS3 Custom properties, Flexbox, Grid
ES6+ JavaScript Modules, Classes, async/await
Canvas API Analog gauge rendering
Geolocation API GPS position and speed tracking
Service Worker Offline functionality & caching
Web App Manifest PWA installation

๐Ÿ“ Project Structure

Speedometer/
โ”œโ”€โ”€ index.html              # Main HTML entry point
โ”œโ”€โ”€ public/
โ”‚   โ”œโ”€โ”€ manifest.json       # PWA manifest
โ”‚   โ”œโ”€โ”€ sw.js               # Service Worker
โ”‚   โ””โ”€โ”€ icons/              # App icons
โ”‚       โ””โ”€โ”€ icon.svg
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ css/
โ”‚   โ”‚   โ””โ”€โ”€ speedometer.css # Styles (OneDark theme)
โ”‚   โ”œโ”€โ”€ js/
โ”‚   โ”‚   โ”œโ”€โ”€ app.js          # Main entry point
โ”‚   โ”‚   โ”œโ”€โ”€ gps.js          # GPS module
โ”‚   โ”‚   โ”œโ”€โ”€ speed.js        # Speed processing & smoothing
โ”‚   โ”‚   โ”œโ”€โ”€ animation.js    # Canvas gauge renderer
โ”‚   โ”‚   โ””โ”€โ”€ ui.js           # UI management
โ”‚   โ””โ”€โ”€ utils/
โ”‚       โ”œโ”€โ”€ haversine.js    # Distance calculation
โ”‚       โ””โ”€โ”€ kalman.js       # Kalman filter for GPS smoothing
โ”œโ”€โ”€ LICENSE
โ””โ”€โ”€ README.md

๐Ÿš€ Getting Started

Prerequisites

  • A modern web browser (Chrome, Firefox, Safari, Edge)
  • A local HTTP server (GPS requires secure context)

Installation

  1. Clone the repository

    git clone https://github.com/mamdous-usual/Speedometer.git
    cd Speedometer
  2. Start a local server

    Using Python:

    python3 -m http.server 8000

    Using Node.js:

    npx serve .

    Using PHP:

    php -S localhost:8000
  3. Open in browser

    http://localhost:8000
    

VS Code Live Server

Alternatively, install the "Live Server" extension and click "Go Live" on index.html.

๐Ÿš€ Deployment

Vercel (Recommended)

  1. Push your code to GitHub
  2. Import the repository on Vercel
  3. Deploy with default settings - no configuration needed

GitHub Pages

For GitHub Pages deployment, you'll need to adjust paths in index.html, manifest.json, sw.js, and app.js to include your repository name prefix (e.g., /Speedometer/).

๐Ÿ“– Usage

  1. Click "Start" to begin GPS tracking
  2. Allow location permission when prompted
  3. Move around (walk, bike, drive) to see your speed
  4. Toggle views using the analog/digital buttons in the header
  5. Switch themes with the sun/moon icon
  6. Click "Reset" to clear trip statistics

Desktop Testing (Without GPS Movement)

  1. Open Chrome DevTools (F12)
  2. Click โ‹ฎ โ†’ More tools โ†’ Sensors
  3. Under "Location", select Custom location
  4. Change coordinates periodically to simulate movement

โš™๏ธ Configuration

Speed Settings

Edit src/js/speed.js:

const config = {
  maxSpeed: 200,           // Maximum speed on gauge (km/h)
  smoothingAlpha: 0.25,    // EMA smoothing factor (0-1)
  minSpeedThreshold: 0.5,  // Speeds below this show as 0
};

Gauge Appearance

Edit src/js/animation.js:

this.config = {
  minSpeed: 0,
  maxSpeed: 200,
  startAngle: -225,        // Gauge start angle
  endAngle: 45,            // Gauge end angle
  tickMajorCount: 10,      // Major tick marks
  tickMinorCount: 4,       // Minor ticks between majors
};

๐ŸŽจ Theming

The app uses the OneDark color scheme. Customize in src/css/speedometer.css:

/* Dark Theme */
[data-theme="dark"] {
  --color-bg-primary: #282c34;
  --color-accent: #61afef;
  --gauge-low: #98c379;    /* Green: 0-60 km/h */
  --gauge-mid: #e5c07b;    /* Yellow: 60-120 km/h */
  --gauge-high: #e06c75;   /* Red: 120+ km/h */
}

/* Light Theme */
[data-theme="light"] {
  --color-bg-primary: #fafafa;
  --color-accent: #4078f2;
}

๐Ÿ”ง Technical Details

Speed Calculation

Method Description
Primary Uses coords.speed from Geolocation API (m/s โ†’ km/h)
Fallback Calculates speed using Haversine distance formula

Smoothing Algorithm

Uses Exponential Moving Average (EMA) with configurable alpha:

smoothedSpeed = ฮฑ ร— currentSpeed + (1 - ฮฑ) ร— previousSpeed

Geolocation Options

{
  enableHighAccuracy: true,  // Use GPS for best accuracy
  maximumAge: 0,             // No cached positions
  timeout: 5000              // 5 second timeout
}

๐ŸŒ Browser Support

Browser Version Support
Chrome 60+ โœ… Full
Firefox 55+ โœ… Full
Safari 11.1+ โœ… Full
Edge 79+ โœ… Full
iOS Safari 11.3+ โœ… Full
Chrome Android 60+ โœ… Full

๐Ÿ“ฑ PWA Installation

Mobile (Android/iOS)

  1. Open the app in your browser
  2. Tap "Add to Home Screen" (or Share โ†’ Add to Home Screen on iOS)
  3. The app will be installed with an icon

Desktop (Chrome/Edge)

  1. Look for the install icon (โŠ•) in the address bar
  2. Click "Install"

The app will work offline after first load!

๐Ÿ–ผ๏ธ Generating App Icons

Convert the SVG icon to PNG at various sizes:

# Using ImageMagick
convert public/icons/icon.svg -resize 192x192 public/icons/icon-192x192.png
convert public/icons/icon.svg -resize 512x512 public/icons/icon-512x512.png

Or use Real Favicon Generator

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments


Made with โค๏ธ using vanilla JavaScript
No frameworks. No dependencies. Just pure web.

About

A GPS speedometer PWA with analog/digital views, dark/light themes. No dependencies.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published