offset method
Returns a destination point based on the given distance and bearing
Given a from (start) point, initial bearing, and distance,
this will calculate the destination point and
final bearing travelling along a (shortest distance) great circle arc.
final Haversine distance = const Haversine();
final double distanceInMeter = earthRadius * pi / 4;
final p1 = LatLng(0.0, 0.0);
final p2 = distance.offset(p1, distanceInMeter, 180);
Implementation
@override
LatLng offset(
final LatLng from, final double distanceInMeter, final double bearing) {
if (bearing < -180 || bearing > 180) {
throw ArgumentError.value(
bearing, 'bearing', 'Angle must be between -180 and 180 degrees');
}
final h = degToRadian(bearing.toDouble());
final a = distanceInMeter / equatorRadius;
final lat2 = asin(sin(from.latitudeInRad) * cos(a) +
cos(from.latitudeInRad) * sin(a) * cos(h));
final lng2 = from.longitudeInRad +
atan2(sin(h) * sin(a) * cos(from.latitudeInRad),
cos(a) - sin(from.latitudeInRad) * sin(lat2));
return LatLng(radianToDeg(lat2), radianToDeg(lng2));
}