Skip to content

Instantly share code, notes, and snippets.

@nissuk
Created April 11, 2012 15:23
Show Gist options
  • Save nissuk/2360016 to your computer and use it in GitHub Desktop.
Save nissuk/2360016 to your computer and use it in GitHub Desktop.
2地点の緯度と経度から距離を計算する
import static java.lang.Math.*;
public class Main {
public static void main(String[] args) {
double r = 6378.137; // 赤道半径[km]
// 大垣駅(lat = 緯度, lng = 経度)
double lat1 = 35.366944 * PI / 180;
double lng1 = 136.617833 * PI / 180;
// ソフトピアジャパン センタービル
double lat2 = 35.367572 * PI / 180;
double lng2 = 136.639661 * PI / 180;
// 2点間の距離[km]
double distance = r * acos(sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(lng2 - lng1));
System.out.printf("%f km", distance);
}
}
@nissuk
Copy link
Author

nissuk commented Apr 27, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment