Skip to main content

Geographic Utilities

Edge-Utils provides powerful geographic utilities for location-aware applications, enabling intelligent routing, location detection, and geographic optimizations.

Features

  • Location Detection: Automatic user location detection
  • Nearest Endpoint Routing: Route to closest endpoints
  • Geographic Load Balancing: Distribute load based on geography
  • Distance Calculations: Calculate distances between coordinates
  • Geocoding: Convert addresses to coordinates
  • Region Optimization: Optimize for regional performance

Location Detection

Automatically detect user location from requests.

Advanced Location Detection

Nearest Endpoint Routing

Route requests to the nearest available endpoint.

Advanced Routing

Geographic Load Balancing

Distribute traffic based on geographic factors.

Dynamic Load Balancing

Distance Calculations

Calculate distances between geographic coordinates.

Advanced Distance Calculations

Geocoding

Convert addresses to geographic coordinates.

Reverse Geocoding

Region Optimization

Optimize applications for specific geographic regions.

Geographic Caching

Cache content based on geographic location.

Platform-Specific Geographic Features

Cloudflare Workers

Vercel Edge Functions

Best Practices

1. Privacy Considerations

2. Fallback Strategies

3. Performance Optimization

API Reference

LocationDetector

  • detect(request, options) - Detect location from request
  • detectByIP(ip) - Detect location from IP address
  • enhance(location) - Enhance location data with additional info
  • hasConsent(request) - Check if user has consented to location tracking

NearestEndpointRouter

  • findNearest(coordinates) - Find nearest endpoint
  • findNearestHealthy(coordinates) - Find nearest healthy endpoint
  • findNearestBalanced(coordinates, options) - Find nearest with load balancing

GeoLoadBalancer

  • selectEndpoint(location) - Select optimal endpoint for location
  • updateLatency(endpointId, latency) - Update endpoint latency
  • adjustWeight(regionId, weight) - Adjust region weight

DistanceCalculator

  • haversine(point1, point2) - Calculate haversine distance
  • vincenty(point1, point2) - Calculate vincenty distance
  • batchCalculate(origin, points) - Calculate distances to multiple points

Geocoder

  • geocode(address) - Convert address to coordinates
  • reverseGeocode(coordinates) - Convert coordinates to address
  • batchGeocode(addresses) - Geocode multiple addresses