Skip to content

Instantly share code, notes, and snippets.

@seventhmoon
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seventhmoon/f3e05ea2df09c59e91fd to your computer and use it in GitHub Desktop.
Save seventhmoon/f3e05ea2df09c59e91fd to your computer and use it in GitHub Desktop.
Convert LatLong to Meter
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