This project is a real-time device tracking application built using Node.js, Express, Socket.IO, and Leaflet.js. It allows multiple devices to share their live locations on a map in real time. The application is designed to track devices and display their positions dynamically on a map interface.
- Real-Time Tracking: Tracks the live location of multiple devices simultaneously.
- Interactive Map: Uses Leaflet.js to display a map with markers for each device.
- Dynamic Updates: Updates device positions in real time using WebSockets (Socket.IO).
- Cross-Device Support: Works on any device with a modern browser and geolocation support.
- Re-center Button: Allows users to re-center the map to their current location.
-
Node.js
- A JavaScript runtime built on Chrome's V8 engine, used to build the backend server.
- Handles client connections, processes location data, and broadcasts updates.
-
Express
- A minimal and flexible Node.js web application framework.
- Used to serve the frontend (HTML, CSS, JS) and handle routing.
-
Socket.IO
- A library for real-time, bidirectional communication between clients and the server.
- Enables real-time updates of device locations across all connected clients.
-
Leaflet.js
- A lightweight, open-source JavaScript library for interactive maps.
- Provides the map interface and handles markers for device locations.
-
HTML, CSS, JavaScript
- Used to build the frontend interface and handle user interactions.
Before running the project, ensure you have the following installed:
- Node.js (v16 or higher)
- npm (Node Package Manager, comes with Node.js)
- A modern web browser with geolocation support (e.g., Chrome, Firefox, Edge)
Open your terminal or command prompt and run:
git clone https://github.com/your-username/realtime-tracking-app.gitNavigate to the project directory:
cd realtime-tracking-appInstall the required dependencies using npm:
npm installThis will install:
- Express
- Socket.IO
- Other dependencies listed in
package.json
Run the following command to start the server:
node app.jsThe server will start running on port 3000. You should see the following message in the terminal:
Server running on port 3000
Open your web browser and navigate to:
http://localhost:3000
Allow the browser to access your location when prompted. You should see a map with your current location marked.
- Open Command Prompt.
- Run
ipconfig. - Look for the IPv4 Address under your active network adapter.
- Open Terminal.
- Run
ifconfigorip addr. - Look for the
inetaddress under your active network adapter.
On another device connected to the same network, open a browser and navigate to:
http://<your-IPv4-address>:3000
Example: If your IPv4 address is 192.168.1.100, use:
http://192.168.1.100:3000
Allow location access when prompted. Both devices will now show their live locations on the map in real-time.
realtime-tracking-app/
├── node_modules/ # Node.js dependencies
├── public/ # Static files (CSS, JS, images)
│ ├── css/
│ │ └── style.css # Custom styles for the app
│ ├── js/
│ │ └── script.js # Client-side JavaScript logic
│ └── favicon.ico # App icon
├── views/
│ └── index.ejs # Main HTML template
├── app.js # Backend server logic
├── package.json # Project dependencies and scripts
├── package-lock.json # Lock file for dependencies
└── README.md # Project documentation
- The browser uses the Geolocation API to fetch the device's current coordinates.
- The coordinates are sent to the server via Socket.IO.
- The server receives the coordinates and broadcasts them to all connected clients.
- It also handles client disconnections and removes their markers from the map.
Each client listens for updates and dynamically adds/updates markers on the map.
- Map Style: Customize the map style by using different tile layers from providers like Mapbox or OpenStreetMap.
- Marker Icons: Replace the default Leaflet markers with custom icons.
- Additional Features: Add features like device names, popups, or routes.
- Ensure your browser has permission to access your device's location.
- Check if the Geolocation API is supported by your browser.
- Verify that the server is running and clients are connected.
- Check the browser console for errors.
- Ensure both devices are connected to the same network.
- Verify that the firewall allows incoming connections on port 3000.
This project is licensed under the MIT License. See the LICENSE file for details.
- Leaflet.js for the interactive map.
- Socket.IO for real-time communication.
- OpenStreetMap for the map tiles.
Enjoy tracking devices in real time! 🚀