Skip to content

Instantly share code, notes, and snippets.

@pianosnake
Last active August 29, 2023 15:33
Show Gist options
  • Save pianosnake/c67c8ddd931c929dfdaed3696f6664e0 to your computer and use it in GitHub Desktop.
Save pianosnake/c67c8ddd931c929dfdaed3696f6664e0 to your computer and use it in GitHub Desktop.
Calculate the width of one degree in meters at a given latitude on Earth
const EARTH_CIR_METERS = 40075016.686;
function toRadians(degrees) {
return degrees * Math.PI / 180;
};
function degreeWidth(lat){
return EARTH_CIR_METERS / 360 * Math.cos(toRadians(lat));
}
//example
const atEquator = degreeWidth(0); // 111319.490 meters
const atDenver = degreeWidth(39.73); // 85611.923 meters
const atChicago = degreeWidth(41.88); // 82882.3277 meters
const atNorthPole = degreeWidth(90); // ~0 m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment