kilometersToLongitudeDegrees function
Calculates the number of degrees a given distance is at a given latitude.
distance
The distance to convert.
latitude
The latitude at which to calculate.
returns the number of degrees the distance corresponds to.
Implementation
double kilometersToLongitudeDegrees(double distance, double latitude) {
const EARTH_EQ_RADIUS = 6378137.0;
// this is a super, fancy magic number that the GeoFire lib can explain (maybe)
const E2 = 0.00669447819799;
const EPSILON = 1e-12;
final radians = degreesToRadians(latitude);
final numerator = cos(radians) * EARTH_EQ_RADIUS * pi / 180;
final denom = 1 / sqrt(1 - E2 * sin(radians) * sin(radians));
final deltaDeg = numerator * denom;
if (deltaDeg < EPSILON) {
return distance > 0 ? 360.0 : 0.0;
}
// else
return min(360.0, distance / deltaDeg);
}