Skip to content

Instantly share code, notes, and snippets.

@mustafasevgi
Created January 29, 2015 14:02
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 mustafasevgi/dbfae7eccad177090d0a to your computer and use it in GitHub Desktop.
Save mustafasevgi/dbfae7eccad177090d0a to your computer and use it in GitHub Desktop.
calculate two location
private String getDistanceBetweenTwoLocations(double latA, double lngA, double latB, double lngB, String suffix) {
Location locationA = new Location("point A");
locationA.setLatitude(latA);
locationA.setLongitude(lngA);
Location locationB = new Location("point B");
locationB.setLatitude(latB);
locationB.setLongitude(lngB);
float distance = locationA.distanceTo(locationB) / 1000;
DecimalFormat df = new DecimalFormat("0.##");
String dst = df.format(distance) + suffix;
return dst;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment