Skip to content

Instantly share code, notes, and snippets.

@sakurabird
Last active December 24, 2015 21:58
Show Gist options
  • Select an option

  • Save sakurabird/6869023 to your computer and use it in GitHub Desktop.

Select an option

Save sakurabird/6869023 to your computer and use it in GitHub Desktop.
Android 緯度経度から2点間の距離をメートルで返す
/**
* 緯度経度から2点間の距離をメートルで返す
*
* @param lat_a
* @param lng_a
* @param lat_b
* @param lng_b
* @return
*/
public static double getDistance(double lat_a, double lng_a, double lat_b, double lng_b) {
Location locationA = new Location("point A");
locationA.setLatitude(lat_a);
locationA.setLongitude(lng_a);
Location locationB = new Location("point B");
locationB.setLatitude(lat_b);
locationB.setLongitude(lng_b);
double distance = locationA.distanceTo(locationB);
return distance;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment