Created
April 23, 2014 17:28
-
-
Save PauloLuan/11225131 to your computer and use it in GitHub Desktop.
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
/** | |
* Calculate the distance between two geopoints (Latitude and Longitude) | |
* in WGS84 | |
* | |
* @param latitudeOne | |
* @param longituteOne | |
* @param latituteTwo | |
* @param longituteTwo | |
* | |
* @return distance the distance in kilometers | |
*/ | |
public static double calculateDistance( | |
double latitudeOne, | |
double longituteOne, | |
double latituteTwo, | |
double longituteTwo) { | |
double AVERAGE_RADIUS_OF_EARTH = 6371; | |
double latDistance = Math.toRadians(latitudeOne - latituteTwo); | |
double lngDistance = Math.toRadians(longituteOne - longituteTwo); | |
double a = (Math.sin(latDistance / 2) * Math.sin(latDistance / 2)) + (Math.cos(Math.toRadians(latitudeOne))) * (Math.cos(Math.toRadians(latituteTwo))) * (Math.sin(lngDistance / 2)) * (Math.sin(lngDistance / 2)); | |
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); | |
double distance = AVERAGE_RADIUS_OF_EARTH * c; | |
return distance; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment