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 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
GeoLatLng offset(final GeoLatLng from, final double distanceInMeter,
final double bearing) {
GValidate.inclusiveBetween(-180.0, 180.0, bearing,
"Angle must be between -180 and 180 degrees but was $bearing");
final double h = degToRadian(bearing.toDouble());
final double a = distanceInMeter / EQUATOR_RADIUS;
final double lat2 = math.asin(math.sin(from.latitudeInRad) * math.cos(a) +
math.cos(from.latitudeInRad) * math.sin(a) * math.cos(h));
final double lng2 = from.longitudeInRad +
math.atan2(math.sin(h) * math.sin(a) * math.cos(from.latitudeInRad),
math.cos(a) - math.sin(from.latitudeInRad) * math.sin(lat2));
return new GeoLatLng(radianToDeg(lat2), radianToDeg(lng2));
}