This repository hosts a Proof of Concept (POC) for a real-time geolocation tracking application specifically designed for vehicles. It provides a full-stack solution demonstrating how to register vehicles, capture their geographic location periodically using a mobile application, and display this historical data on a web-based dashboard.
The application is built using the MERN (MongoDB, Express.js, React, Node.js) stack, ensuring a robust and scalable architecture:
- Mobile App: Developed with React Native for cross-platform compatibility (iOS and Android).
- Backend API: Powered by Node.js and Express.js to handle user registration and location data storage.
- Database: MongoDB is used to persist vehicle registration details and their corresponding geolocation data.
- Web UI: A React.js application serves as a simple dashboard to fetch and visualize the historical location data.
This project can serve as a foundational block for more advanced vehicle tracking systems, fleet management solutions, or any application requiring real-time GPS tracking and location history.
- Geolocation Tracking
- Real-time Location
- Vehicle Tracking
- GPS Tracker App
- MERN Stack
- React Native
- Node.js Express.js
- MongoDB
- Web UI Dashboard
- Location History
- Cross-platform Mobile Development
- Fleet Management (POC)
- IoT (Internet of Things) Location
- User Registration Screen:
- Allows users to register their vehicles with a unique Vehicle ID and Vehicle Type.
- Submits registration data securely to the backend.
- Location Permission Handling:
- Prompts the user to grant necessary location permissions (foreground and background).
- Background Location Tracking:
- Periodically collects geolocation data (latitude, longitude, timestamp) in the background (e.g., every 5 minutes, configurable).
- Sends the captured location data to the backend API.
- Fetch and Display Location Data:
- Fetches the geolocation history for registered vehicles from the backend.
- Displays the data in a clear, tabular format including Timestamp, Latitude, and Longitude.
- Provides a simple interface without extensive styling for this POC.
- RESTful API Endpoints:
POST /register: Endpoint to save new vehicle registration information.POST /location: Endpoint to receive and store periodic geolocation updates.GET /locations: Endpoint to fetch the geolocation history for display on the web UI.
- User Registration:
- A user opens the
mobile-app, inputs their Vehicle ID and Vehicle Type, and submits. - The backend saves this information to MongoDB.
- A user opens the
- Location Tracking:
- The user grants location permissions to the
mobile-app. - The
mobile-appstarts tracking the device's location and periodically sends the geolocation data to the backend. - The backend stores this data in MongoDB.
- The user grants location permissions to the
- Data Display:
- The
web-uifetches the historical location data for a specific vehicle (or all, depending on implementation detail) using a backend API endpoint. - The
web-uidisplays this data in a list/table format.
- The
Follow these steps to set up and run the entire application locally.
Ensure you have the following installed on your development machine:
- Node.js (LTS version recommended, v18.x or higher) - Download from nodejs.org.
- npm (comes with Node.js)
- Expo CLI: Install globally using npm:
npm install -g expo-cli
- MongoDB:
- Install MongoDB locally (refer to the MongoDB Installation Guide).
- Alternatively, use a cloud service like MongoDB Atlas for a free tier database.
The backend handles API requests for user registration and location data.
- Clone the repository:
git clone <your-repo-url> cd <your-repo-name>
- Navigate to the backend directory:
cd backend - Install Dependencies:
npm install
- Set Up MongoDB Connection:
- Create a
config.jsfile in thebackenddirectory (if not already present). - Add your MongoDB connection string to this file. Replace the placeholder with your actual URI.
If using MongoDB Atlas, your URI will look different and include credentials and possibly a database name.
// backend/config.js module.exports = { mongoURI: 'mongodb://localhost:27017/geolocation_tracker' // Replace with your MongoDB URI (e.g., from MongoDB Atlas) };
- Create a
- Run the Backend Server:
The backend server should now be running, typically on
npm start
http://localhost:5000(checkserver.jsfor the exact port).
The mobile app is responsible for vehicle registration and continuous location tracking.
- Navigate to the mobile-app directory:
cd ../mobile-app - Install Dependencies:
npm install
- Configure Backend API URL:
- You'll need to update the API URL in the mobile app to point to your backend server.
- Open
mobile-app/App.js(or a similar file where API calls are made) and replacehttp://localhost:5000with your backend server's IP address if running on a physical device on the same network. For example, if your computer's local IP is192.168.1.10, usehttp://192.168.1.10:5000. If running on an emulator,http://localhost:5000orhttp://10.0.2.2:5000(for Android emulator) might work.
- Run the Mobile App:
This will open the Expo Dev Tools in your browser.
npx expo start
- For Android: Scan the QR code using the Expo Go app on your Android device.
- For iOS: Open the Expo Go app on your iOS device and scan the QR code.
- On Emulator/Simulator: You can select options within the Expo Dev Tools (e.g., 'Run on Android emulator', 'Run on iOS simulator') to deploy the app.
The web UI displays the collected geolocation history.
- Navigate to the web-ui directory:
cd ../web-ui - Install Dependencies:
npm install
- Configure Backend API URL:
- Similar to the mobile app, you'll likely need to configure the API URL that the web UI fetches data from.
- Check files like
web-ui/src/App.jsorweb-ui/src/services/api.jsfor the API base URL. Ensure it points to your backend server (e.g.,http://localhost:5000).
- Run the Web UI:
The web UI should automatically open in your browser, typically at
npm start
http://localhost:3000.
Once all three components are set up and running:
- Start the Backend Server (
npm startin thebackenddirectory). - Run the Mobile App (
npx expo startin themobile-appdirectory) on an emulator or physical device.- Register a new vehicle through the mobile app's registration screen (e.g., Vehicle ID:
TRK001, Vehicle Type:Car). - Grant location permissions to the app when prompted. The app will then start tracking your device's location and sending data to the backend periodically.
- Register a new vehicle through the mobile app's registration screen (e.g., Vehicle ID:
- Launch the Web UI (
npm startin theweb-uidirectory) in your browser.- The web UI should now fetch and display the geolocation history for the registered vehicle. You may need to refresh the web page after some time to see new location points appear.
.
├── backend/ # Node.js/Express.js API
│ ├── models/ # MongoDB schemas (e.g., Vehicle, Location)
│ ├── routes/ # API endpoint definitions (e.g., /register, /location, /locations)
│ ├── config.js # MongoDB connection string configuration
│ ├── server.js # Main server file, initializes Express and connects to MongoDB
│ └── package.json # Backend dependencies
├── mobile-app/ # React Native application (Expo managed)
│ ├── components/ # Reusable UI components
│ ├── screens/ # Individual app screens (e.g., RegistrationScreen, TrackerScreen)
│ ├── services/ # API service calls
│ ├── App.js # Main app component, handles navigation and initial setup
│ └── package.json # Mobile app dependencies
└── web-ui/ # React.js web dashboard
├── src/
│ ├── components/ # Reusable UI components for the web UI
│ ├── services/ # API service calls for the web UI
│ ├── App.js # Main web app component
│ └── index.js # Entry point for the React web app
└── package.json # Web UI dependencies
- Mobile App: A basic React Native application with vehicle registration and periodic location tracking.
- Backend API: Minimal Node.js/Express.js endpoints for user registration and location data storage/retrieval.
- Web UI: A basic React.js page to view the geolocation history in a list/table format.
This project is a Proof of Concept (POC), and contributions are highly welcome to enhance its features, improve styling, add more robust error handling, implement user authentication, and extend functionality (e.g., real-time map display, filtering, etc.).
Feel free to fork the repository, make your changes, and submit a pull request.