A modern web application that tracks user location in real-time using Google Maps and displays it with a blue dot marker. Built with Next.js, TypeScript, and Tailwind CSS.
- 🗺️ Google Maps Integration: Interactive map with real-time location display
- 📍 Real-time Tracking: Continuous location updates with blue dot marker
- 🔐 Permission Management: Proper geolocation permission handling
- 📱 Cross-device Support: Works on desktop, tablet, and mobile devices
- 🎯 Accurate Positioning: High-accuracy GPS with fallback support
- 🎨 Modern UI: Clean, responsive design with Tailwind CSS
- ⚡ Real-time Updates: Live location tracking with visual feedback
- 📦 PWA Support: Installable app with offline fallback page
Before running this application, you need:
- Google Maps API Key - Get one from Google Cloud Console
- Node.js (v18 or higher)
- pnpm package manager
# Install dependencies
pnpm install- Go to Google Cloud Console
- Create a new project or select an existing one
- Enable the following APIs:
- Maps JavaScript API
- Geocoding API (optional)
- Create credentials (API Key)
- Restrict the API key for security:
- Add your domain to HTTP referrers
- Enable only the required APIs
Create a .env.local file in the root directory:
# Create environment file
touch .env.localAdd your Google Maps API key:
NEXT_PUBLIC_GOOGLE_MAPS_API_KEY=your_actual_api_key_herepnpm devOpen http://localhost:3000 in your browser.
- The app includes a web app manifest and a service worker (
public/sw.js). - Install prompts appear in supported browsers after the first successful load.
- An offline fallback page is available at
/offlinewhen the network is unavailable. - In development, service workers work on
http://localhostonly; for other hosts use HTTPS.
- Enter Your Name: Fill in the name input field
- Request Location Permission: Click "Start Tracking" to allow location access
- View Your Location: Your position appears as a blue dot on the map
- Real-time Updates: The map automatically follows your movement
- Stop Tracking: Click "Stop Tracking" to end location monitoring
Map: Google Maps integration with location markerControlButtons: Start/stop tracking controls with status indicatorsNameInput: User name input fielduseLocationTracking: Custom hook for geolocation management
- Permission Handling: Graceful handling of location permissions
- Error Management: Comprehensive error handling for various scenarios
- Responsive Design: Optimized for all screen sizes
- Performance: Efficient location updates with proper cleanup
- Accessibility: Proper ARIA labels and keyboard navigation
Works on all modern browsers that support:
- Geolocation API
- ES6+ JavaScript features
- CSS Grid and Flexbox
- Optimized touch controls
- Responsive map controls
- Proper viewport handling
- Battery-efficient location tracking
-
"Location Access Denied"
- Check browser location permissions
- Ensure HTTPS in production
- Verify API key restrictions
-
Map Not Loading
- Verify Google Maps API key
- Check API key restrictions
- Ensure Maps JavaScript API is enabled
-
Location Not Updating
- Check device GPS settings
- Verify location permissions
- Try refreshing the page
- Use browser developer tools to monitor location permissions
- Check console for API key errors
- Test on actual mobile devices for best results
- Push to GitHub
- Connect to Vercel
- Add environment variables in Vercel dashboard
- Deploy
Ensure the following for production deployment:
- HTTPS enabled (required for geolocation)
- Environment variables properly configured
- API key restrictions updated for production domain
- API keys are exposed to the client (necessary for Maps API)
- Use API key restrictions to limit usage
- Monitor API usage in Google Cloud Console
- Consider implementing server-side API key management for sensitive operations
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
MIT License - feel free to use in your projects.