planarDistance static method

double planarDistance(
  1. double lat1,
  2. double lon1,
  3. double lat2,
  4. double lon2,
)

Calculates the distance between two points using a simplified planar approximation (Pythagorean theorem).

Note: This is only accurate for short distances (< 10km). For longer distances, use haversineDistance.

Parameters:

  • lat1: Latitude of point 1 in decimal degrees
  • lon1: Longitude of point 1 in decimal degrees
  • lat2: Latitude of point 2 in decimal degrees
  • lon2: Longitude of point 2 in decimal degrees

Returns: Approximate distance in meters

Implementation

static double planarDistance(
  double lat1,
  double lon1,
  double lat2,
  double lon2,
) {
  // Convert to meters (approximate)
  final latDiff = (lat2 - lat1) * 111320; // meters per degree latitude
  final lonDiff = (lon2 - lon1) *
      111320 *
      cos(degreesToRadians((lat1 + lat2) / 2)); // adjust for latitude

  return sqrt(latDiff * latDiff + lonDiff * lonDiff);
}