Skip to content
sksalapurPublic

About

Real-time school bus tracking Android app - live GPS every 4s, per-stop Haversine ETA, FCM proximity alerts, role-based UI (student/driver/admin)

Topics

Resources

Stars

4 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

13 Commits

Folders and files

Repository files navigation

🚌 NextStop

Your bus is 3 minutes away. We checked.

Real-time school bus tracking with live GPS, per-stop ETA, geofenced polylines,
and push notifications β€” built entirely in Kotlin with Jetpack Compose.


πŸ€” The Problem

Every parent and student has asked the same question: "Where is the bus?"

Current solutions are either:

  • πŸ“ž Phone calls β€” "Driver, where are you?" (annoying for everyone)
  • πŸ“ WhatsApp location sharing β€” unreliable, battery-draining, no ETA
  • πŸ’° Commercial fleet trackers β€” expensive, designed for logistics companies, not schools

NextStop is purpose-built for schools. Students see their bus on a live map, get a per-stop ETA, and receive a push notification when the bus is approaching their stop. Admins manage the entire fleet β€” routes, buses, drivers, stops β€” from a single dashboard.


⚑ How It Works

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     NextStop System                             β”‚
β”‚                                                                 β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                        β”‚
β”‚  β”‚  DRIVER APP         β”‚                                        β”‚
β”‚  β”‚  Foreground Service β”‚                                        β”‚
β”‚  β”‚  β”œβ”€β”€ FusedLocation  │──── GPS ping every 4s ────┐            β”‚
β”‚  β”‚  β”‚   (HIGH_ACCURACY)β”‚                           β”‚            β”‚
β”‚  β”‚  β”œβ”€β”€ Speed filter   β”‚                           β–Ό            β”‚
β”‚  β”‚  β”‚   (>0.5 m/s)     β”‚             β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”‚
β”‚  β”‚  └── Bearing data   β”‚             β”‚ Firebase Realtime β”‚      β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜             β”‚ Database          β”‚      β”‚
β”‚                                      β”‚ /live/{busId}     β”‚      β”‚
β”‚                                      β”‚ β”œβ”€β”€ latitude      β”‚      β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”               β”‚ β”œβ”€β”€ longitude     β”‚      β”‚
β”‚  β”‚  STUDENT APP      │◄──── Live ────│ β”œβ”€β”€ speed         β”‚      β”‚
β”‚  β”‚                   β”‚   listener    β”‚ β”œβ”€β”€ bearing       β”‚      β”‚
β”‚  β”‚  β”œβ”€β”€ Google Map   β”‚               β”‚ β”œβ”€β”€ timestamp     β”‚      β”‚
β”‚  β”‚  β”‚   with route   β”‚               β”‚ └── active        β”‚      β”‚
β”‚  β”‚  β”‚   polyline     β”‚               β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β”‚
β”‚  β”‚  β”‚                β”‚                                          β”‚
β”‚  β”‚  β”œβ”€β”€ Per-stop ETA β”‚    Haversine distance Γ· current speed    β”‚
β”‚  β”‚  β”‚   computation  β”‚    = minutes to each stop                β”‚
β”‚  β”‚  β”‚                β”‚                                          β”‚
β”‚  β”‚  β”œβ”€β”€ Proximity    β”‚    If ETA < 5 min for assigned stop      β”‚
β”‚  β”‚  β”‚   notification β”‚    β†’ Firebase Cloud Messaging push       β”‚
β”‚  β”‚  β”‚                β”‚                                          β”‚
β”‚  β”‚  └── Stop progressβ”‚    Animated progress bar with bus icon   β”‚
β”‚  β”‚      bar          β”‚    tracking across the route             β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                          β”‚
β”‚                                                                 β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”‚
β”‚  β”‚  ADMIN DASHBOARD   β”‚              β”‚ Cloud Firestore  β”‚       β”‚
β”‚  β”‚                    │◄────────────►│                  β”‚       β”‚
β”‚  β”‚  β”œβ”€β”€ Manage Buses  β”‚              β”‚ /buses           β”‚       β”‚
β”‚  β”‚  β”œβ”€β”€ Manage Routes β”‚              β”‚ /routes          β”‚       β”‚
β”‚  β”‚  β”œβ”€β”€ Assign Driversβ”‚              β”‚ /users           β”‚       β”‚
β”‚  β”‚  β”œβ”€β”€ CRUD Stops    β”‚              β”‚ /assignments     β”‚       β”‚
β”‚  β”‚  └── Fleet tracker β”‚              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜       β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

✨ Features

πŸ‘¨β€πŸŽ“ Student Experience

πŸ“ Live GPS Tracking

  • Real-time bus position on a Google Map with custom bus marker icon
  • Location updates every 4 seconds via FusedLocationProviderClient at PRIORITY_HIGH_ACCURACY
  • Location freshness indicator: "● Live" (green), "● 3 min ago" (yellow), "● Offline" (red) β€” students always know how fresh the data is

⏱️ Intelligent ETA

  • Per-stop ETA computation: Haversine distance from bus coordinates to each stop, divided by current GPS speed
  • Boarding stop ETA: Personalized "Arrives at your stop in 4 min" β€” not a generic fleet-wide estimate
  • Edge case handling: "Calculating...", "Bus has already passed", "Bus is far away"

πŸ”” Smart Boarding Alerts

  • Set your personal boarding stop using Google Places Autocomplete (restricted to India)
  • Toggle proximity notifications β€” get a push when the bus is approaching your stop
  • Stop assignments persist in Firestore β€” works across app restarts

πŸ—ΊοΈ Dynamic Route Visualization

  • Google Directions API polylines: Road-snapped route paths (not naive straight lines between stops)
  • Geofenced stop progression: "Passed" stops dim into gray, "Next" stop highlights in primary color
  • Animated progress bar: Bus icon slides across a stop-by-stop progress track with smooth animateFloatAsState transitions
  • Bottom sheet map: BottomSheetScaffold with draggable stop list + map overlay

πŸ”„ Direction Toggle

  • To College / To Home / All Scheduled β€” filter buses by trip direction
  • Only shows buses that pass through your boarding stop (unless viewing "All Scheduled")

πŸ‘‘ Administrator Dashboard

🚍 Fleet Management CRUD

  • Buses: Create, edit, assign numbers and types
  • Routes: Define routes with ordered stops, departure times, assigned buses
  • Stops: Add stops via Google Places Autocomplete with lat/lng auto-fill, reorder with drag handles
  • Drivers: Assign drivers to buses, manage authentication and roster

πŸ“Š Live Fleet Tracking

  • Mirror any active route on the admin dashboard β€” see exactly what students see
  • Fleet-wide overview of which buses are active, inactive, or offline

πŸ› οΈ Tech Stack

Layer Technology Why This Choice
UI Jetpack Compose + Material 3 Declarative UI with BottomSheetScaffold, AnimatedContent
Language Kotlin 2.0 Coroutines, StateFlow, type-safe throughout
Architecture MVVM + StateFlow + Dagger Hilt DI Clean separation, testable, injectable
Auth Firebase Auth Role-based: Student / Driver / Admin
Metadata DB Cloud Firestore Routes, buses, stops, users, assignments
Realtime DB Firebase Realtime Database Live GPS coordinates β€” low latency, high write throughput
Maps Google Maps SDK (Compose) Vector overlays, Polylines, Markers, Camera animations
Places Google Places API (New) Autocomplete restricted to IN region for stop selection
Directions Google Directions API Road-snapped polyline computation between stops
Location FusedLocationProviderClient High-accuracy GPS with configurable intervals
Foreground Service LocationForegroundService + Binder Persistent tracking that survives app backgrounding
Notifications Firebase Cloud Messaging Per-stop proximity push alerts

πŸ“ Project Structure

NextStop/
β”œβ”€β”€ app/src/main/java/com/yourteam/nextstop/
β”‚   β”œβ”€β”€ data/repository/
β”‚   β”‚   β”œβ”€β”€ AdminRepository.kt        # Fleet CRUD operations
β”‚   β”‚   β”œβ”€β”€ AuthRepository.kt         # Firebase Auth + role detection
β”‚   β”‚   β”œβ”€β”€ DriverRepository.kt       # Live location writes to RTDB
β”‚   β”‚   └── StudentRepository.kt      # Stop assignments, bus tracking
β”‚   β”‚
β”‚   β”œβ”€β”€ di/
β”‚   β”‚   └── AppModule.kt              # Dagger Hilt module β€” Firebase, Maps
β”‚   β”‚
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   β”œβ”€β”€ Bus.kt, Route.kt, User.kt # Domain models
β”‚   β”‚   β”œβ”€β”€ LiveLocation.kt           # RTDB GPS data class
β”‚   β”‚   β”œβ”€β”€ TripState.kt              # Sealed class: Running | Stopped
β”‚   β”‚   └── CollegeLocation.kt        # Campus coordinates
β”‚   β”‚
β”‚   β”œβ”€β”€ service/
β”‚   β”‚   β”œβ”€β”€ LocationForegroundService.kt  # GPS tracking service (4s interval)
β”‚   β”‚   └── ProximityNotificationService.kt # FCM push notification handler
β”‚   β”‚
β”‚   β”œβ”€β”€ ui/
β”‚   β”‚   β”œβ”€β”€ student/
β”‚   β”‚   β”‚   β”œβ”€β”€ StudentHomeScreen.kt       # Fleet dashboard with direction toggle
β”‚   β”‚   β”‚   β”œβ”€β”€ StudentViewModel.kt        # Live bus tracking, ETA computation
β”‚   β”‚   β”‚   └── HomeStopSetupScreen.kt     # Boarding stop selection
β”‚   β”‚   β”œβ”€β”€ driver/
β”‚   β”‚   β”‚   β”œβ”€β”€ DriverHomeScreen.kt        # Trip start/stop with speed display
β”‚   β”‚   β”‚   └── DriverViewModel.kt         # Foreground service binding
β”‚   β”‚   β”œβ”€β”€ admin/
β”‚   β”‚   β”‚   β”œβ”€β”€ AdminHomeScreen.kt         # Tab layout: Dashboard, Manage, Assign
β”‚   β”‚   β”‚   β”œβ”€β”€ AdminDashboardTab.kt       # Live fleet overview
β”‚   β”‚   β”‚   β”œβ”€β”€ AdminManageTab.kt          # Buses, Routes, Stops CRUD
β”‚   β”‚   β”‚   └── AdminViewModel.kt          # Fleet management state
β”‚   β”‚   β”œβ”€β”€ auth/
β”‚   β”‚   β”‚   β”œβ”€β”€ LoginScreen.kt             # Email/password + role selection
β”‚   β”‚   β”‚   └── AuthViewModel.kt           # Auth state machine
β”‚   β”‚   └── components/
β”‚   β”‚       β”œβ”€β”€ TrackingComponents.kt      # SharedTrackerScreen, BusTrackingMap, StopProgressBar
β”‚   β”‚       β”œβ”€β”€ CustomPlacesSearchField.kt # Google Places autocomplete widget
β”‚   β”‚       β”œβ”€β”€ ShimmerSkeleton.kt         # Loading skeleton components
β”‚   β”‚       └── NextStopTopBar.kt          # Reusable top app bar
β”‚   β”‚
β”‚   β”œβ”€β”€ util/
β”‚   β”‚   β”œβ”€β”€ LocationUtils.kt              # Haversine, ETA, vector bitmap helpers
β”‚   β”‚   └── DirectionsFetcher.kt          # Google Directions API polyline decoder
β”‚   β”‚
β”‚   └── navigation/
β”‚       β”œβ”€β”€ AppNavigation.kt              # Role-based navigation graph
β”‚       └── NavRoutes.kt                  # Route definitions
β”‚
β”œβ”€β”€ google-services.json                   # Firebase config (gitignored)
└── build.gradle.kts

πŸš€ Getting Started

Prerequisites

  • Android Studio Ladybug+ Β· Kotlin 2.0
  • Firebase project (Auth + Firestore + Realtime Database)
  • Google Cloud project with Maps SDK, Places API, Directions API enabled

Setup

  1. Clone the repo
  2. Place google-services.json in app/
  3. Add your Maps API key to local.properties:
    MAPS_API_KEY=YOUR_GOOGLE_MAPS_API_KEY
  4. Sync Gradle and run on your device

Firebase Structure

Collection/Path Purpose
users/{uid} User profile with role (student/driver/admin)
buses/{busId} Bus metadata (number, type, capacity)
routes/{routeId} Route with ordered stops, departure time, assigned bus
assignments/{id} Driver ↔ Bus ↔ Route assignments
live/{busId} (RTDB) Real-time GPS coordinates (4s updates)

Never ask "where is the bus?" again.
Real-time tracking, built for schools, powered by Kotlin.

Made with ❀️ by Shashank Salapur

About

Real-time school bus tracking Android app - live GPS every 4s, per-stop Haversine ETA, FCM proximity alerts, role-based UI (student/driver/admin)

Topics

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages