Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distance calculation #8

Closed
tablacus opened this issue Feb 21, 2017 · 0 comments
Closed

Distance calculation #8

tablacus opened this issue Feb 21, 2017 · 0 comments

Comments

@tablacus
Copy link

距離を近似式で求めるJavaScriptの関数を作ってみました。
現在地と近い順に並べたりするのに使うのであれば、この程度の精度でも良いのではないかと思います。

//calcDistance(緯度1, 経度1, 緯度2, 経度2)
//2点間の距離(km)を近似式で求めます。
//x に紀伊田辺駅(33.733058, 135.384144)と串本駅(33.475527, 135.781603)の距離を求める場合
//x = calcDistance(33.733058, 135.384144, 33.475527, 135.781603);

function calcDistance(n1, t1, n2, t2)
{
  var r = 3.1415926535 / 180;
  n1 *= r;
  t1 *= r;
  n1 -= ((11.55 / 60) * r) * Math.sin(2 * n1);
  n2 *= r;
  t2 *= r;
  n2 -= ((11.55 / 60) * r) * Math.sin(2 * n2);
  var c = Math.cos(n1) * Math.cos(n2) * Math.cos(t1 - t2) + Math.sin(n1) * Math.sin(n2);
  return Math.atan2(Math.sqrt(1 - c * c), c) * 6369;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants