Last active
August 29, 2015 14:21
-
-
Save seventhmoon/f3e05ea2df09c59e91fd to your computer and use it in GitHub Desktop.
Convert LatLong to Meter
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
private double calcDist(double lat1, double lng1, double lat2, double lng2) { | |
double earthRadius = 3958.75; | |
double lat = Math.toRadians(lat2 - lat1); | |
double lng = Math.toRadians(lng2 - lng1); | |
double a = Math.sin(lat / 2) * Math.sin(lat / 2) | |
+ Math.cos(Math.toRadians(lat1)) | |
* Math.cos(Math.toRadians(lat2)) * Math.sin(lng / 2) | |
* Math.sin(lng / 2); | |
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); | |
double dist = earthRadius * c; | |
int meterConversion = 1609; | |
return dist * meterConversion; | |
// return new Float(dist * meterConversion).floatValue(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment