Skip to content

Instantly share code, notes, and snippets.

@clesauln
Created January 15, 2018 19:35
Show Gist options
  • Save clesauln/59ac090e16e9f0178018e67b47041757 to your computer and use it in GitHub Desktop.
Save clesauln/59ac090e16e9f0178018e67b47041757 to your computer and use it in GitHub Desktop.
convert rad to tiles js
Math.radians = function(degrees) {
return degrees * Math.PI / 180;
};
var zoom = 8;
var lon = 5.2206592;
var lat = 49.1154095;
var xtile = Math.floor(((lon+180)/360) * Math.pow(2,zoom));
var ytile = Math.floor((1- Math.log(Math.atan(Math.radians(lat)) + 1 / Math.cos(Math.radians(lat))) / Math.PI) / 2 * Math.pow(2,zoom));
console.log('xtile: ' + xtile);
console.log('ytile: ' + ytile);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment