Created
August 26, 2017 12:02
-
-
Save patrickyin/9bdbb0d1a419fbc0cf029300e9f1af21 to your computer and use it in GitHub Desktop.
TilePosition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public TilePosition getTilePosition(float zoomLevel, double latitude, double longitude) { | |
int tileZoom = round(zoomLevel); | |
int tileX = (int) ((longitude + 180.0) / 360.0 * pow(2.0, tileZoom)); | |
int tileY = (int)((1.0 - log(tan(latitude * PI / 180.0) + 1.0 / cos(latitude * PI / 180.0)) / PI) / 2.0 * pow(2.0, tileZoom)); | |
tileY = (int) (pow(2.0, tileZoom) - tileY - 1.0); // flip Y, this is only for mbtiles file | |
return new TilePosition(tileZoom, tileX, tileY); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment