Created
April 11, 2012 15:23
-
-
Save nissuk/2360016 to your computer and use it in GitHub Desktop.
2地点の緯度と経度から距離を計算する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://log.nissuk.info/2012/04/2.html