Skip to content

itsiamdev/geolocation-api

Repository files navigation

πŸ—ΊοΈ Geolocation API Web App

Geolocation App Screenshot

πŸ“– Project Overview

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/

🌟 Key Features

πŸ“ Advanced Location Detection

  • 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

πŸ—ΊοΈ Interactive Mapping Experience

  • 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

🏠 Intelligent Address Resolution

  • 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

πŸ”„ Real-Time Location Tracking

  • 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

πŸ“Š Data Visualization & Analytics

  • 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

🎨 Modern User Interface

  • 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

πŸ“± Cross-Platform Compatibility

  • 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

πŸ—οΈ Architecture & Technology Stack

Frontend Framework

  • 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

Mapping & Geospatial

  • Leaflet.js: Lightweight, open-source mapping library
  • OpenStreetMap: Free, editable map of the world
  • Nominatim: OpenStreetMap's geocoding service

UI/UX & Styling

  • 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

State Management & Data Fetching

  • React Query (TanStack Query): Powerful data synchronization for React
  • Custom Hooks: Reusable logic for geolocation and geocoding operations

Development Tools

  • ESLint: Code linting and formatting
  • PostCSS: CSS processing and optimization
  • TypeScript Compiler: Advanced type checking and compilation

πŸ”§ How It Works

  1. Permission Request: The app requests location access from the browser
  2. GPS Acquisition: Device GPS/hardware obtains current coordinates
  3. Data Processing: Coordinates are processed and accuracy is calculated
  4. Map Rendering: Location is displayed on the interactive map
  5. Geocoding: Reverse geocoding fetches address information
  6. Real-time Updates: Continuous monitoring if live tracking is enabled

🌐 Browser Support

  • βœ… Chrome 60+
  • βœ… Firefox 55+
  • βœ… Safari 11+
  • βœ… Edge 79+
  • βœ… Mobile browsers (iOS Safari, Chrome Mobile)

Requires HTTPS for geolocation access in production environments.

πŸš€ Getting Started

πŸ“‹ Prerequisites

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

πŸ› οΈ Installation & Setup

  1. πŸ“₯ Clone the Repository

    git clone https://github.com/your-username/geolocation-api.git
    cd geolocation-api
  2. πŸ“¦ Install Dependencies

    npm install
    # or
    yarn install
  3. πŸ”§ Environment Configuration (if needed)

    # Copy environment template
    cp .env.example .env.local
    # Edit .env.local with your configuration
  4. ▢️ Start Development Server

    npm run dev
    # or
    yarn dev
  5. 🌐 Access the Application Open your browser and navigate to http://localhost:8080

πŸ—οΈ Build for Production

# Create optimized production build
npm run build

# Preview production build locally
npm run preview

# Deploy the dist/ folder to your web server

πŸ“š Project Structure

geolocation-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

πŸ› οΈ Technology Stack & Dependencies

Core Framework

  • βš›οΈ 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

Mapping & Geospatial

  • πŸ—ΊοΈ 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

UI/UX & Styling

  • 🎨 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

State Management & Data Fetching

  • πŸ” 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

Development & Build Tools

  • πŸ“ 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

Development Dependencies

  • πŸ§ͺ 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

πŸ”Œ API Reference

Geolocation API Integration

The application integrates with the following browser APIs:

Navigator.geolocation

// 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);

Nominatim API (OpenStreetMap)

// 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();

Custom Hooks

useGeolocation

const {
  latitude,
  longitude,
  accuracy,
  loading,
  error,
  supported,
  getPosition,
  startWatching,
  stopWatching
} = useGeolocation();

useReverseGeocode

const { address, loading, getAddress } = useReverseGeocode();

πŸš€ Deployment

Vercel (Recommended)

  1. Connect your GitHub repository to Vercel
  2. Configure build settings:
    • Build Command: npm run build
    • Output Directory: dist
    • Install Command: npm install
  3. Add environment variables if needed
  4. Deploy automatically on push

Netlify

  1. Connect repository to Netlify
  2. Set build command: npm run build
  3. Set publish directory: dist
  4. Configure redirects for SPA routing

Manual Deployment

# Build the application
npm run build

# Deploy the dist/ folder to your web server
# Ensure the server supports HTTPS for geolocation API

πŸ”’ Privacy & Security

Data Handling

  • 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

Security Considerations

  • Content Security Policy: Implemented to prevent XSS attacks
  • Secure Headers: Appropriate security headers configured
  • API Rate Limiting: Respectful usage of external geocoding services

πŸ§ͺ Testing

Running Tests

# Run unit tests
npm run test

# Run tests in watch mode
npm run test:watch

# Run tests with coverage
npm run test:coverage

Test Coverage

  • Component testing with React Testing Library
  • Hook testing with custom utilities
  • Integration tests for critical user flows

🀝 Contributing

We welcome contributions! Please follow these guidelines:

Development Workflow

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit your changes: git commit -m 'Add amazing feature'
  4. Push to the branch: git push origin feature/amazing-feature
  5. Open a Pull Request

Code Standards

  • Follow TypeScript best practices
  • Use ESLint configuration
  • Write meaningful commit messages
  • Add tests for new features
  • Update documentation as needed

Issue Reporting

  • Use GitHub Issues for bug reports and feature requests
  • Provide detailed reproduction steps
  • Include browser and device information
  • Attach screenshots for UI issues

πŸ“Š Performance

Optimization Features

  • 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

Performance Metrics

  • First Contentful Paint: < 1.5s
  • Largest Contentful Paint: < 2.5s
  • First Input Delay: < 100ms
  • Cumulative Layout Shift: < 0.1

🌍 Internationalization

Supported Languages

  • πŸ‡·πŸ‡΄ Romanian (primary)
  • πŸ‡ΊπŸ‡Έ English
  • πŸ‡©πŸ‡ͺ German
  • πŸ‡«πŸ‡· French

Adding New Languages

  1. Create translation files in src/locales/
  2. Update language switcher component
  3. Add language to build configuration

πŸ“ž Support & Community

Getting Help

  • πŸ“§ Email: ionitaaurel32@gmail.com
  • πŸ› Issues: GitHub Issues for bug reports
  • πŸ“– Documentation: Comprehensive docs available

Community Guidelines

  • Be respectful and inclusive
  • Provide constructive feedback
  • Help other community members
  • Follow our code of conduct

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • 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

About

🌍 Geolocation API Web App A lightweight web app that detects and displays your real-time location using the browser’s Geolocation API πŸ“. ⚑ Fast, simple, and perfect for learning how location-based features work in web development. ✨ Features: πŸ“Œ Live coordinates 🌐 Built-in browser API πŸ”’ Permission-based access

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages