A full-stack application that tracks the user's current location using the browser's Geolocation API, converts the coordinates to a human-readable address using the OpenCage Data API, and displays the location on a Google Map. The location data is also stored in a MongoDB database and logged in a local text file for analysis.
- axios: For making HTTP requests to the backend API
- cors: Enables Cross-Origin Resource Sharing
- dotenv: Loads environment variables from .env file
- express: Web framework for Node.js
- mongoose: Object Data Modeling library for MongoDB
-
Clone the repository:
git clone https://github.com/yourusername/LiveLocationTracking.git
-
Navigate to the project directory:
cd LiveLocationTracking -
Install dependencies for both frontend and backend:
npm install cd backend npm install -
Create a
.envfile in the root directory as well as in backend folder and include your API keys and port:OPENCAGE_API_KEY=your_opencage_api_key_here GOOGLE_MAPS_API_KEY=your_google_maps_api_key_here PORT=5000
-
Install nodemon globally (optional but recommended for development):
npm install -g nodemon
- Click the "Get Current Location" button on the frontend.
- Allow location access when prompted by your browser.
- The application will display your latitude and longitude.
- Reverse geocoding will retrieve and display your full address and formatted address.
- A Google Map will load dynamically, marking your current location.
- Your location data will be saved in MongoDB and appended to the
locations.txtfile.
- Start the backend server:
cd backend nodemon server.js - Open the frontend in your browser by opening
frontend/index.html
-
Billing for Google Maps API:
Ensure billing is enabled for your Google Cloud project; otherwise, you might encounter aBillingNotEnabledMapError. -
API Keys:
Your API keys are stored in the.envfile. Do not expose these keys publicly.
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a new branch for your feature
- Commit your changes
- Push to the branch
- Create a Pull Request