distanceTo method
- GeoPoint other
Calculates the distance to another location (in meters)
Implementation
double distanceTo(GeoPoint other) {
const double earthRadius = 6371000; // meters
final lat1 = location.latitude * (3.14159265359 / 180); // Convert to radians
final lon1 = location.longitude * (3.14159265359 / 180);
final lat2 = other.latitude * (3.14159265359 / 180);
final lon2 = other.longitude * (3.14159265359 / 180);
final dLat = lat2 - lat1;
final dLon = lon2 - lon1;
final a =
math.sin(dLat/2) * math.sin(dLat/2) +
math.cos(lat1) * math.cos(lat2) *
math.sin(dLon/2) * math.sin(dLon/2);
final c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a));
return earthRadius * c;
}