A sophisticated, modern web application built with cutting-edge technologies that empowers users to explore their geographical location through advanced GPS technology. This application seamlessly integrates the browser's Geolocation API with interactive mapping capabilities, providing users with real-time location data, precise coordinates, and comprehensive address information through reverse geocoding services.
The app features a responsive, mobile-first design with smooth animations and a glass-morphism aesthetic, ensuring an exceptional user experience across all devices. Whether you're a developer testing location-based features, a traveler documenting your journey, or simply curious about your exact position on the planet, this tool provides accurate, privacy-conscious location insights.
Live Demo: iam269.github.io/geolocation-api/
- High-Precision GPS: Utilizes the browser's Geolocation API to obtain accurate latitude and longitude coordinates
- Accuracy Reporting: Displays location precision in meters, helping users understand data reliability
- Permission Management: Graceful handling of location permissions with clear user guidance
- OpenStreetMap Integration: Powered by Leaflet.js and OpenStreetMap for detailed, open-source mapping
- Dynamic Zoom & Pan: Smooth map interactions with automatic centering on user location
- Custom Markers: Visual indicators showing exact location with accuracy radius overlays
- Multiple Map Layers: Support for different map styles and satellite imagery
- Reverse Geocoding: Automatic conversion of coordinates to human-readable addresses
- Nominatim API: Integration with OpenStreetMap's geocoding service for comprehensive address data
- Multi-language Support: Address information in local languages where available
- Live Monitoring: Continuous location updates with configurable intervals
- Movement Visualization: Track position changes over time on the map
- Battery Optimization: Efficient tracking that minimizes device battery drain
- Location History: Optional storage of location data for analysis
- Accuracy Metrics: Real-time display of GPS signal strength and precision
- Export Capabilities: Options to export location data in various formats
- Glass-Morphism Design: Contemporary UI with translucent elements and blur effects
- Smooth Animations: Powered by Framer Motion for fluid transitions
- Dark/Light Mode: Adaptive theming based on user preferences
- Accessibility: WCAG-compliant design with keyboard navigation and screen reader support
- Responsive Layout: Optimized for smartphones, tablets, and desktop computers
- Progressive Web App: Installable on mobile devices with offline capabilities
- Touch-Friendly: Intuitive touch gestures for mobile interaction
- Cross-Browser Support: Compatible with all modern web browsers
- React 18: Modern React with concurrent features and hooks
- TypeScript: Type-safe development with comprehensive type definitions
- Vite: Lightning-fast build tool and development server
- Leaflet.js: Lightweight, open-source mapping library
- OpenStreetMap: Free, editable map of the world
- Nominatim: OpenStreetMap's geocoding service
- Tailwind CSS: Utility-first CSS framework for rapid styling
- shadcn/ui: High-quality, accessible UI components
- Framer Motion: Production-ready motion library for React
- Lucide Icons: Beautiful, consistent icon set
- React Query (TanStack Query): Powerful data synchronization for React
- Custom Hooks: Reusable logic for geolocation and geocoding operations
- ESLint: Code linting and formatting
- PostCSS: CSS processing and optimization
- TypeScript Compiler: Advanced type checking and compilation
- Permission Request: The app requests location access from the browser
- GPS Acquisition: Device GPS/hardware obtains current coordinates
- Data Processing: Coordinates are processed and accuracy is calculated
- Map Rendering: Location is displayed on the interactive map
- Geocoding: Reverse geocoding fetches address information
- Real-time Updates: Continuous monitoring if live tracking is enabled
- β Chrome 60+
- β Firefox 55+
- β Safari 11+
- β Edge 79+
- β Mobile browsers (iOS Safari, Chrome Mobile)
Requires HTTPS for geolocation access in production environments.
Before you begin, ensure you have the following installed on your system:
- Node.js (version 18.0.0 or higher) - Download here
- npm (comes with Node.js) or yarn package manager
- Git for version control
- A modern web browser with geolocation support
-
π₯ Clone the Repository
git clone https://github.com/your-username/geolocation-api.git cd geolocation-api -
π¦ Install Dependencies
npm install # or yarn install -
π§ Environment Configuration (if needed)
# Copy environment template cp .env.example .env.local # Edit .env.local with your configuration
-
βΆοΈ Start Development Servernpm run dev # or yarn dev -
π Access the Application Open your browser and navigate to
http://localhost:8080
# Create optimized production build
npm run build
# Preview production build locally
npm run preview
# Deploy the dist/ folder to your web servergeolocation-api/
βββ public/ # Static assets
β βββ favicon.ico
β βββ robots.txt
βββ src/
β βββ components/ # Reusable UI components
β β βββ ui/ # Base UI components (shadcn/ui)
β β βββ Header.tsx
β β βββ LocationButton.tsx
β β βββ ...
β βββ hooks/ # Custom React hooks
β β βββ useGeolocation.ts
β β βββ useReverseGeocode.ts
β βββ pages/ # Page components
β β βββ Index.tsx
β β βββ NotFound.tsx
β βββ lib/ # Utility functions
β βββ App.tsx # Main app component
βββ package.json # Dependencies and scripts
βββ vite.config.ts # Vite configuration
βββ tailwind.config.ts # Tailwind CSS configuration
βββ README.md # Project documentation
- βοΈ React 18.2+: Modern React with concurrent features, hooks, and server components support
- π· TypeScript 5.0+: Type-safe JavaScript with advanced type inference
- π§ Vite 4.0+: Next-generation frontend tooling for fast development
- πΊοΈ Leaflet 1.9+: Lightweight, open-source JavaScript library for interactive maps
- π OpenStreetMap: Free, editable map of the world with community-driven data
- π Nominatim API: OpenStreetMap's geocoding service for address lookup
- π¨ Tailwind CSS 3.3+: Utility-first CSS framework for rapid UI development
- π§© shadcn/ui: High-quality, accessible component library built on Radix UI
- π Framer Motion 10.0+: Production-ready motion library for React animations
- π Lucide Icons: Beautiful, consistent icon set with React components
- π TanStack Query 4.0+: Powerful data synchronization for React applications
- π‘ Geolocation API: Native browser API for accessing device location
- π React Router 6.0+: Declarative routing for React applications
- π ESLint: Pluggable linting utility for JavaScript and TypeScript
- π― PostCSS: Tool for transforming CSS with JavaScript plugins
- π¦ npm/yarn: Package managers for JavaScript dependencies
- π¨ TypeScript Compiler: Advanced type checking and compilation
- π§ͺ Vitest: Fast unit test framework powered by Vite
- π @testing-library/react: Simple and complete testing utilities
- π― Husky: Git hooks made easy
- π Commitlint: Linting for commit messages
The application integrates with the following browser APIs:
// Get current position
navigator.geolocation.getCurrentPosition(
(position) => {
const { latitude, longitude, accuracy } = position.coords;
// Handle successful location acquisition
},
(error) => {
// Handle location error
},
{
enableHighAccuracy: true,
timeout: 10000,
maximumAge: 300000
}
);
// Watch position for continuous updates
const watchId = navigator.geolocation.watchPosition(
(position) => {
// Handle position updates
},
(error) => {
// Handle watch error
}
);
// Stop watching
navigator.geolocation.clearWatch(watchId);// Reverse geocoding request
const response = await fetch(
`https://nominatim.openstreetmap.org/reverse?format=json&lat=${latitude}&lon=${longitude}&zoom=18&addressdetails=1`
);
const data = await response.json();const {
latitude,
longitude,
accuracy,
loading,
error,
supported,
getPosition,
startWatching,
stopWatching
} = useGeolocation();const { address, loading, getAddress } = useReverseGeocode();- Connect your GitHub repository to Vercel
- Configure build settings:
- Build Command:
npm run build - Output Directory:
dist - Install Command:
npm install
- Build Command:
- Add environment variables if needed
- Deploy automatically on push
- Connect repository to Netlify
- Set build command:
npm run build - Set publish directory:
dist - Configure redirects for SPA routing
# Build the application
npm run build
# Deploy the dist/ folder to your web server
# Ensure the server supports HTTPS for geolocation API- No Data Storage: Location data is never stored on servers
- Client-Side Processing: All location processing happens in the browser
- User Consent: Location access requires explicit user permission
- HTTPS Required: Geolocation API requires secure context
- Content Security Policy: Implemented to prevent XSS attacks
- Secure Headers: Appropriate security headers configured
- API Rate Limiting: Respectful usage of external geocoding services
# Run unit tests
npm run test
# Run tests in watch mode
npm run test:watch
# Run tests with coverage
npm run test:coverage- Component testing with React Testing Library
- Hook testing with custom utilities
- Integration tests for critical user flows
We welcome contributions! Please follow these guidelines:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
- Follow TypeScript best practices
- Use ESLint configuration
- Write meaningful commit messages
- Add tests for new features
- Update documentation as needed
- Use GitHub Issues for bug reports and feature requests
- Provide detailed reproduction steps
- Include browser and device information
- Attach screenshots for UI issues
- Code Splitting: Automatic code splitting with Vite
- Lazy Loading: Components loaded on demand
- Image Optimization: Optimized asset loading
- Caching: Intelligent caching strategies
- Bundle Analysis: Tools for bundle size monitoring
- First Contentful Paint: < 1.5s
- Largest Contentful Paint: < 2.5s
- First Input Delay: < 100ms
- Cumulative Layout Shift: < 0.1
- π·π΄ Romanian (primary)
- πΊπΈ English
- π©πͺ German
- π«π· French
- Create translation files in
src/locales/ - Update language switcher component
- Add language to build configuration
- π§ Email: ionitaaurel32@gmail.com
- π Issues: GitHub Issues for bug reports
- π Documentation: Comprehensive docs available
- Be respectful and inclusive
- Provide constructive feedback
- Help other community members
- Follow our code of conduct
This project is licensed under the MIT License - see the LICENSE file for details.
- OpenStreetMap contributors for the amazing map data
- Leaflet team for the excellent mapping library
- shadcn for the beautiful UI components
- React community for the fantastic ecosystem
Made with β€οΈ by the iam269
