destinationPoint method

GeoPoint destinationPoint({
  1. required double distanceInMeters,
  2. required dynamic bearingInDegrees,
})

destinationPoint

this method will calculate new GeoPoint using giving distance distanceInMeters using bearingInDegrees we will determine direction of that GeoPoint

return GeoPoint

Implementation

GeoPoint destinationPoint(
    {required double distanceInMeters, required bearingInDegrees}) {
  // convert distance to angular distance
  final double dist = distanceInMeters / earthRadiusMeters;

  // convert bearing to radians
  final double brng = deg2rad * bearingInDegrees;

  // get current location in radians
  final double lat1 = deg2rad * latitude;
  final double lon1 = deg2rad * longitude;

  final double lat2 =
      asin(sin(lat1) * cos(dist) + cos(lat1) * sin(dist) * cos(brng));
  final double lon2 = lon1 +
      atan2(sin(brng) * sin(dist) * cos(lat1),
          cos(dist) - sin(lat1) * sin(lat2));

  final double lat2deg = lat2 / deg2rad;
  final double lon2deg = lon2 / deg2rad;

  return GeoPoint(
    latitude: lat2deg,
    longitude: lon2deg,
  );
}