Skip to content

raydot/react-native-geolocation-tester

Repository files navigation

React Native GPS Accuracy Checker

A React Native application designed to test GPS geolocation accuracy against established USGS benchmarks. This single-screen app compares GPS readings against a benchmark location and provides comprehensive statistical analysis of location accuracy.

🎯 Project Overview

Built to test GPS accuracy against known surveyed benchmarks from the National Geodetic Survey (NGS). Successfully tested on two benchmarks in Marin County, CA with real-world accuracy validation.

Key Features

  • Single GPS reading: Get one-time location reading
  • Continuous tracking: Watch position changes in real-time
  • Distance calculation: Haversine formula implementation for precise distance calculations
  • Statistical analysis: Real-time statistics including mean, standard deviation, min/max distances
  • Cross-platform support: Handles iOS and Android location permissions
  • User-friendly interface: Clean, responsive design with coordinate input and real-time display

πŸ—οΈ Architecture

Core Architecture

  • Single-file app structure: The entire app logic is contained in App.tsx
  • No navigation library: Single screen application with all functionality on one view
  • State management: Uses React hooks (useState, useEffect) for local state management
  • No external API dependencies: All processing is done client-side

Key Dependencies

  • @react-native-community/geolocation: Core geolocation functionality
  • react-native-permissions: Handles location permission requests across platforms
  • react-native-safe-area-context: Safe area handling for different device types

Technical Stack

  • Languages: JavaScript/TypeScript, JSX
  • Framework: React Native with CLI (not Expo - chosen for full native access to precise GPS APIs)
  • Native APIs: iOS Location Services, Core Location
  • Tools: Xcode, Metro, npm, CocoaPods
  • Libraries: @react-native-community/geolocation
  • Platforms: iOS development and deployment (Android ready)

πŸš€ Getting Started

Note: Make sure you have completed the React Native Environment Setup guide before proceeding.

Prerequisites

  • Node.js >= 18
  • React Native CLI
  • iOS: Xcode and CocoaPods
  • Android: Android Studio and SDK

Installation

  1. Clone the repository
git clone <repository-url>
cd react-native-geolocation-tester
  1. Install dependencies
npm install
  1. iOS setup (required on first clone or after native dependency changes)
bundle install
bundle exec pod install

Running the App

  1. Start Metro bundler
npm start
  1. Run on your target platform

iOS

npm run ios
# OR for device deployment
npx react-native run-ios --device

Android

npm run android

If everything is set up correctly, you should see the GPS Accuracy Checker running on your device or simulator.

Development Tools

# Run linting
npm run lint

# Run tests
npm test

πŸ“± How to Use

  1. Set Benchmark Coordinates: Enter the latitude and longitude of your known benchmark location
  2. Choose Reading Mode:
    • Single Reading: Get one GPS reading to test accuracy
    • Continuous Tracking: Start real-time tracking for statistical analysis
  3. View Results: See distance from benchmark, GPS accuracy, and statistical analysis
  4. Analyze Data: Review recent readings and comprehensive statistics

πŸ”§ Configuration

Benchmark Location

The benchmark coordinates can be set in the app interface or modified in App.tsx:

const [benchmarkLat, setBenchmarkLat] = useState('37.936722');
const [benchmarkLon, setBenchmarkLon] = useState('-122.534278');

GPS Configuration

The app uses high-accuracy GPS settings:

  • enableHighAccuracy: true
  • timeout: 15000ms
  • maximumAge: 0 (no cached readings)
  • distanceFilter: 0 (get all position updates)

πŸ“Š Testing Methodology

The app implements a comprehensive GPS accuracy testing framework:

  1. Distance Calculation: Uses the Haversine formula to calculate precise distances between GPS readings and the benchmark location
  2. Statistical Analysis: Provides real-time statistics including mean, standard deviation, min/max distances
  3. Accuracy Tracking: Records both the GPS-reported accuracy and actual distance from known location
  4. Historical Data: Maintains reading history with timestamps for analysis

πŸ› οΈ Development Insights

React Native Concepts Learned

  • Project Setup: CLI vs Expo trade-offs for native API access
  • State Management: React hooks for location data and UI state
  • Native Integration: iOS/Android permission handling differences
  • Performance: Location tracking cleanup and battery considerations

Mobile Development Best Practices

  • Permissions: Platform-specific location permission requirements
  • Real Device Testing: GPS functionality requires physical devices
  • User Experience: Input validation, error handling, responsive design
  • Performance: Proper cleanup of location watchers

Mathematical Implementation

  • Haversine Formula: Great-circle distance calculations
  • Statistical Analysis: Real-time computation of accuracy metrics
  • Coordinate Systems: DMS to decimal degree conversion support

πŸ” Troubleshooting

Location Permissions

If location readings fail, check that:

  • Location permissions are granted in device settings
  • Location services are enabled on the device/emulator
  • The app has been granted "precise location" access (iOS 14+)

Metro/Build Issues

  • Clear Metro cache: npx react-native start --reset-cache
  • Clean build: Delete node_modules and run npm install
  • iOS: Clean Xcode build folder and re-run bundle exec pod install

Common Issues

  • Permission errors: Handling location access denied scenarios
  • GPS errors: Timeout, accuracy, and availability issues
  • Certificate/signing issues: Resolving Xcode keychain and provisioning problems
  • Metro bundler troubleshooting: Understanding when to restart vs reload

🎯 Success Metrics

βœ… Functional app deployed to physical iPhone
βœ… Real-world validation tested against two NGS benchmarks
βœ… Accurate measurements confirmed GPS readings vs survey data
βœ… User-friendly interface with coordinate input and real-time display
βœ… Professional development workflow established

πŸš€ Next Steps for Enhancement

  • Android deployment: Extend to Android platform
  • Maps integration: Add visual maps showing GPS readings
  • Data persistence: Save readings to device storage
  • Bluetooth/external GPS: Connect to external GPS receivers
  • Background processing: Continue tracking when app backgrounded
  • UI polish: Custom icons, animations, better styling
  • Testing: Unit tests, integration tests for location functionality
  • V2: Integrate with NGS API to get benchmark data and allow user to enter benchmark number and receive information
  • V3: Integrate with NGS API to create a map of the area and allow user to find benchmarks and test accuracy

πŸ“š Learn More

To learn more about React Native and GPS development:

πŸ“„ License

This project is built with React Native using @react-native-community/cli.

About

React Native Project that allows a user to test their phones geolocation against a known latlng.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published