computeOffset static method

LatLng computeOffset(
  1. LatLng from,
  2. num distance,
  3. num heading
)

Returns the LatLng resulting from moving a distance from an origin in the specified heading (expressed in degrees clockwise from north). @param from The LatLng from which to start. @param distance The distance to travel. @param heading The heading in degrees clockwise from north.

Implementation

static LatLng computeOffset(LatLng from, num distance, num heading) {
  distance /= earthRadius;
  heading = MathUtil.toRadians(heading);
  // http://williams.best.vwh.net/avform.htm#LL
  final fromLat = MathUtil.toRadians(from.latitude);
  final fromLng = MathUtil.toRadians(from.longitude);
  final cosDistance = cos(distance);
  final sinDistance = sin(distance);
  final sinFromLat = sin(fromLat);
  final cosFromLat = cos(fromLat);
  final sinLat =
      cosDistance * sinFromLat + sinDistance * cosFromLat * cos(heading);
  final dLng = atan2(sinDistance * cosFromLat * sin(heading),
      cosDistance - sinFromLat * sinLat);

  return LatLng(MathUtil.toDegrees(asin(sinLat)).toDouble(),
      MathUtil.toDegrees(fromLng + dLng).toDouble());
}