offset static 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 num distanceInMeter = (EARTH_RADIUS * math.PI / 4).round();
final p1 = new LatLng(0.0, 0.0);
final p2 = distance.offset(p1, distanceInMeter, 180);
Implementation
//@override
static ILatLong offset(
final ILatLong from, final double distanceInMeter, double bearing) {
assert(bearing >= 0 && bearing <= 360);
// bearing: 0: north, 90: east, 180: south, 270: west
//bearing = 90 - bearing;
// 0: east, 90: north, +/- 180: west, -90: south
final double h = bearing / 180 * pi;
final double a = distanceInMeter / EQUATORIAL_RADIUS;
final double lat2 = asin(sin(degToRadian(from.latitude)) * cos(a) +
cos(degToRadian(from.latitude)) * sin(a) * cos(h));
final double lng2 = degToRadian(from.longitude) +
atan2(sin(h) * sin(a) * cos(degToRadian(from.latitude)),
cos(a) - sin(degToRadian(from.latitude)) * sin(lat2));
return new LatLong(radianToDeg(lat2), radianToDeg(lng2));
}