Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save codeswimmer/901677 to your computer and use it in GitHub Desktop.

Select an option

Save codeswimmer/901677 to your computer and use it in GitHub Desktop.
Android: calculate the distance between two locations
public static final float[] calculateDistanceTo(Location fromLocation, Location toLocation) {
float[] results = new float[];
double startLatitude = fromLocation.getLatitude();
double startLongitude = fromLocation.getLongitude();
double endLatitude = toLocation.getLatitude();
double endLongitude = toLocation.getLongitude();
fromLocation.distanceBetween(startLatitude, startLongitude, endLatitude, endLongitude, results);
return results;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment