4 * The MIT License (MIT)
5 * Copyright(C) 2007-2012 やまだらけ
6 * http://yamadarake.jp/trdi/report000001.html
10 * @author やまだらけ yama_darake@yahoo.co.jp
13 public class GeoDistance {
15 public static final double GRS80_A = 6378137.000; // 赤道半径(m)
16 public static final double GRS80_E2 = 0.00669438002301188;
17 public static final double GRS80_MNUM = 6335439.32708317; //
19 public static final double WGS84_A = 6378137.000;
20 public static final double WGS84_E2 = 0.00669437999019758;
21 public static final double WGS84_MNUM = 6335439.32729246;
24 * 角度(180度)をラジアン(2π)に変換する
28 public static double deg2rad(double deg){
29 return deg * Math.PI / 180.0;
40 public static double calcDistHubeny(double lat1, double lng1,
41 double lat2, double lng2){
42 double my = deg2rad((lat1 + lat2) / 2.0); // 平均緯度
43 double dy = deg2rad(lat1 - lat2); // 2点間の緯度
44 double dx = deg2rad(lng1 - lng2); // 2点間の経度
46 double sin = Math.sin(my);
47 double w = Math.sqrt(1.0 - GRS80_E2 * sin * sin);
48 double m = GRS80_MNUM / (w * w * w);
49 double n = GRS80_A / w;
52 double dxncos = dx * n * Math.cos(my);
54 return Math.sqrt(dym * dym + dxncos * dxncos);
58 public static void main(String[] args){
59 System.out.println("Coords Test Program");
60 double lat1, lng1, lat2, lng2;
62 lat1 = Double.parseDouble(args[0]);
63 lng1 = Double.parseDouble(args[1]);
64 lat2 = Double.parseDouble(args[2]);
65 lng2 = Double.parseDouble(args[3]);
67 double d = calcDistHubeny(lat1, lng1, lat2, lng2);
69 System.out.println("Distance = " + d + " m");