Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. public class GetDistanceBetweenLocation{
  2.  
  3. public static double getDistanceBetweenLocations(double originLat, double originLng,double destinationLat, double destinationLng ){
  4.  
  5. int radiusOfEarth = 6371; // Km
  6.  
  7. double dLat = Math.toRadians(destinationLat - originLat);
  8. double dLng = Math.toRadians(destinationLng - originLng);
  9.  
  10. double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(Math.toRadians(originLat)) * Math.cos(Math.toRadians(destinationLat)) * Math.sin(dLng / 2) * Math.sin(dLng / 2);
  11. double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
  12.  
  13. return radiusOfEarth * c;
  14. }
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement