Created
July 24, 2017 21:30
-
-
Save angebagui/cb076fec6eaa7f0d68e716ef380703a5 to your computer and use it in GitHub Desktop.
get Distance Between Location
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment