Skip to content

Instantly share code, notes, and snippets.

@angebagui
Created July 24, 2017 21:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angebagui/cb076fec6eaa7f0d68e716ef380703a5 to your computer and use it in GitHub Desktop.
Save angebagui/cb076fec6eaa7f0d68e716ef380703a5 to your computer and use it in GitHub Desktop.
get Distance Between Location
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