@Test public void pixelYToLatitudeTest() { for (byte zoomLevel = ZOOM_LEVEL_MIN; zoomLevel <= ZOOM_LEVEL_MAX; ++zoomLevel) { double latitude = MercatorProjection.pixelYToLatitude(0, zoomLevel); Assert.assertEquals(MercatorProjection.LATITUDE_MAX, latitude, 0); long mapSize = MercatorProjection.getMapSize(zoomLevel); latitude = MercatorProjection.pixelYToLatitude(mapSize / 2, zoomLevel); Assert.assertEquals(0, latitude, 0); latitude = MercatorProjection.pixelYToLatitude(mapSize, zoomLevel); Assert.assertEquals(MercatorProjection.LATITUDE_MIN, latitude, 0); } }
public static double pixelYToLatitude(double pixelY, byte zoomLevel) { long mapSize = getMapSize(zoomLevel); if (pixelY < 0 || pixelY > mapSize) { throw new IllegalArgumentException("invalid pixelY coordinate at zoom level " + zoomLevel + ": " + pixelY); } double y = 0.5 - (pixelY / mapSize); return 90 - 360 * Math.atan(Math.exp(-y * (2 * Math.PI))) / Math.PI; }
MercatorProjection { public static double pixelYToLatitude(double pixelY, byte zoomLevel) { long mapSize = getMapSize(zoomLevel); if (pixelY < 0 || pixelY > mapSize) { throw new IllegalArgumentException("invalid pixelY coordinate at zoom level " + zoomLevel + ": " + pixelY); } double y = 0.5 - (pixelY / mapSize); return 90 - 360 * Math.atan(Math.exp(-y * (2 * Math.PI))) / Math.PI; } }
MercatorProjection { public static double pixelYToLatitude(double pixelY, byte zoomLevel) { long mapSize = getMapSize(zoomLevel); if (pixelY < 0 || pixelY > mapSize) { throw new IllegalArgumentException("invalid pixelY coordinate at zoom level " + zoomLevel + ": " + pixelY); } double y = 0.5 - (pixelY / mapSize); return 90 - 360 * Math.atan(Math.exp(-y * (2 * Math.PI))) / Math.PI; } private  MercatorProjection(); }
MercatorProjection { public static double pixelYToLatitude(double pixelY, byte zoomLevel) { long mapSize = getMapSize(zoomLevel); if (pixelY < 0 || pixelY > mapSize) { throw new IllegalArgumentException("invalid pixelY coordinate at zoom level " + zoomLevel + ": " + pixelY); } double y = 0.5 - (pixelY / mapSize); return 90 - 360 * Math.atan(Math.exp(-y * (2 * Math.PI))) / Math.PI; } private  MercatorProjection(); static double calculateGroundResolution(double latitude, byte zoomLevel); static double deltaLat(double deltaPixel, double lat, byte zoom); static long getMapSize(byte zoomLevel); static double latitudeToPixelY(double latitude, byte zoomLevel); static long latitudeToTileY(double latitude, byte zoomLevel); static double longitudeToPixelX(double longitude, byte zoomLevel); static long longitudeToTileX(double longitude, byte zoomLevel); static double pixelXToLongitude(double pixelX, byte zoomLevel); static long pixelXToTileX(double pixelX, byte zoomLevel); static double pixelYToLatitude(double pixelY, byte zoomLevel); static long pixelYToTileY(double pixelY, byte zoomLevel); static double tileXToLongitude(long tileX, byte zoomLevel); static double tileYToLatitude(long tileY, byte zoomLevel); }
MercatorProjection { public static double pixelYToLatitude(double pixelY, byte zoomLevel) { long mapSize = getMapSize(zoomLevel); if (pixelY < 0 || pixelY > mapSize) { throw new IllegalArgumentException("invalid pixelY coordinate at zoom level " + zoomLevel + ": " + pixelY); } double y = 0.5 - (pixelY / mapSize); return 90 - 360 * Math.atan(Math.exp(-y * (2 * Math.PI))) / Math.PI; } private  MercatorProjection(); static double calculateGroundResolution(double latitude, byte zoomLevel); static double deltaLat(double deltaPixel, double lat, byte zoom); static long getMapSize(byte zoomLevel); static double latitudeToPixelY(double latitude, byte zoomLevel); static long latitudeToTileY(double latitude, byte zoomLevel); static double longitudeToPixelX(double longitude, byte zoomLevel); static long longitudeToTileX(double longitude, byte zoomLevel); static double pixelXToLongitude(double pixelX, byte zoomLevel); static long pixelXToTileX(double pixelX, byte zoomLevel); static double pixelYToLatitude(double pixelY, byte zoomLevel); static long pixelYToTileY(double pixelY, byte zoomLevel); static double tileXToLongitude(long tileX, byte zoomLevel); static double tileYToLatitude(long tileY, byte zoomLevel); static final double EARTH_CIRCUMFERENCE; static final double LATITUDE_MAX; static final double LATITUDE_MIN; }