Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class GetDistanceBetweenLocation{
- public static double getDistanceBetweenLocations(double originLat, double originLng,double destinationLat, double destinationLng ){
- int radiusOfEarth = 6371; // Km
- double dLat = Math.toRadians(destinationLat - originLat);
- double dLng = Math.toRadians(destinationLng - originLng);
- 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);
- double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
- return radiusOfEarth * c;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement