Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * <p>
- * Calculate the end point of traveling along a great-circle path from a
- * given starting point with a given intitial bearing for a known distance.
- * </p>
- *
- * @param start
- * the starting point.
- * @param initialBearing
- * the initial bearing.
- * @param distance
- * the distance to travel.
- * @param unit
- * the unit in which distance is measured.
- * @return the end point.
- */
- public static LatLng travel(LatLng start, double initialBearing, double distance,
- LengthUnit unit) {
- double bR = Math.toRadians(initialBearing);
- double lat1R = Math.toRadians(start.getLatitude());
- double lon1R = Math.toRadians(start.getLongitude());
- double dR = distance / LatLngConfig.getEarthRadius(unit);
- double a = Math.sin(dR) * Math.cos(lat1R);
- double lat2 = Math.asin(Math.sin(lat1R) * Math.cos(dR) + a * Math.cos(bR));
- double lon2 = lon1R
- + Math.atan2(Math.sin(bR) * a, Math.cos(dR) - Math.sin(lat1R) * Math.sin(lat2));
- return new LatLng(Math.toDegrees(lat2), Math.toDegrees(lon2));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement