planarDistance static method
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 degreeslon1: Longitude of point 1 in decimal degreeslat2: Latitude of point 2 in decimal degreeslon2: 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);
}