Skip to content

Instantly share code, notes, and snippets.

@mumoshu
Created August 3, 2010 00:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mumoshu/505589 to your computer and use it in GitHub Desktop.
Save mumoshu/505589 to your computer and use it in GitHub Desktop.
/*
* 参考: http://blog.livedoor.jp/sawamur/archives/50450768.html
*/
var CIRCLE_IN_METERS = 40000000
/**
* 引数に渡した緯度における経度1秒の長さをメートル単位で返す
* @param {number} latitude -180~+180の緯度
*/
function longitudeInSecondsAtLatitude(latitude) {
/* 赤道(緯度0度)における1ラジアンあたりの東西方向の距離(メートル) */
var metersPerRadian = CIRCLE_IN_METERS /( 2 * Math.PI );
/* 緯度(latitude / 180度)における1ラジアンあたりの東西方向の距離(メートル) */
var r2 = Math.cos( ( latitude / 180 ) * Math.PI ) * metersPerRadian;
var m = (r2 * 2 * Math.PI) / (360 * 60 * 60);
return m;
}
var latitudes = {
"東京": 35,
"那覇": 26,
"札幌": 43
};
for (name in latitudes) {
var latInDegree = latitudes[name];
var metersPerLngInSeconds = longitudeInSecondsAtLatitude(latInDegree);
console.log(name, metersPerLngInSeconds);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment