computeDestination static method

LatLng computeDestination(
  1. LatLng start,
  2. double bearingDeg,
  3. double distanceMeters
)

Computes a destination point given a start point, bearing (degrees), and distance (meters). Uses the Haversine forward formula.

Implementation

static LatLng computeDestination(LatLng start, double bearingDeg, double distanceMeters) {
  final double R = earthRadiusKm * 1000.0; // Earth radius in meters
  final double lat1 = start.latitude * math.pi / 180.0;
  final double lng1 = start.longitude * math.pi / 180.0;
  final double brng = bearingDeg * math.pi / 180.0;
  final double d = distanceMeters / R;

  final double lat2 = math.asin(
    math.sin(lat1) * math.cos(d) + math.cos(lat1) * math.sin(d) * math.cos(brng),
  );
  final double lng2 = lng1 + math.atan2(
    math.sin(brng) * math.sin(d) * math.cos(lat1),
    math.cos(d) - math.sin(lat1) * math.sin(lat2),
  );

  return LatLng(lat2 * 180.0 / math.pi, lng2 * 180.0 / math.pi);
}