Advertisement
Guest User

Untitled

a guest
Oct 1st, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. /**
  2. * <p>
  3. * Calculate the end point of traveling along a great-circle path from a
  4. * given starting point with a given intitial bearing for a known distance.
  5. * </p>
  6. *
  7. * @param start
  8. * the starting point.
  9. * @param initialBearing
  10. * the initial bearing.
  11. * @param distance
  12. * the distance to travel.
  13. * @param unit
  14. * the unit in which distance is measured.
  15. * @return the end point.
  16. */
  17. public static LatLng travel(LatLng start, double initialBearing, double distance,
  18. LengthUnit unit) {
  19. double bR = Math.toRadians(initialBearing);
  20. double lat1R = Math.toRadians(start.getLatitude());
  21. double lon1R = Math.toRadians(start.getLongitude());
  22. double dR = distance / LatLngConfig.getEarthRadius(unit);
  23.  
  24. double a = Math.sin(dR) * Math.cos(lat1R);
  25. double lat2 = Math.asin(Math.sin(lat1R) * Math.cos(dR) + a * Math.cos(bR));
  26. double lon2 = lon1R
  27. + Math.atan2(Math.sin(bR) * a, Math.cos(dR) - Math.sin(lat1R) * Math.sin(lat2));
  28. return new LatLng(Math.toDegrees(lat2), Math.toDegrees(lon2));
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement