@Test public void latitudeToPixelYTest() { for (byte zoomLevel = ZOOM_LEVEL_MIN; zoomLevel <= ZOOM_LEVEL_MAX; ++zoomLevel) { double pixelY = MercatorProjection.latitudeToPixelY(MercatorProjection.LATITUDE_MAX, zoomLevel); Assert.assertEquals(0, pixelY, 0); long mapSize = MercatorProjection.getMapSize(zoomLevel); pixelY = MercatorProjection.latitudeToPixelY(0, zoomLevel); Assert.assertEquals(mapSize / 2, pixelY, 0); pixelY = MercatorProjection.latitudeToPixelY(MercatorProjection.LATITUDE_MIN, zoomLevel); Assert.assertEquals(mapSize, pixelY, 0); } }
public static double latitudeToPixelY(double latitude, byte zoomLevel) { double sinLatitude = Math.sin(latitude * (Math.PI / 180)); long mapSize = getMapSize(zoomLevel); double pixelY = (0.5 - Math.log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * Math.PI)) * mapSize; return Math.min(Math.max(0, pixelY), mapSize); }
MercatorProjection { public static double latitudeToPixelY(double latitude, byte zoomLevel) { double sinLatitude = Math.sin(latitude * (Math.PI / 180)); long mapSize = getMapSize(zoomLevel); double pixelY = (0.5 - Math.log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * Math.PI)) * mapSize; return Math.min(Math.max(0, pixelY), mapSize); } }
MercatorProjection { public static double latitudeToPixelY(double latitude, byte zoomLevel) { double sinLatitude = Math.sin(latitude * (Math.PI / 180)); long mapSize = getMapSize(zoomLevel); double pixelY = (0.5 - Math.log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * Math.PI)) * mapSize; return Math.min(Math.max(0, pixelY), mapSize); } private  MercatorProjection(); }
MercatorProjection { public static double latitudeToPixelY(double latitude, byte zoomLevel) { double sinLatitude = Math.sin(latitude * (Math.PI / 180)); long mapSize = getMapSize(zoomLevel); double pixelY = (0.5 - Math.log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * Math.PI)) * mapSize; return Math.min(Math.max(0, pixelY), mapSize); } 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 latitudeToPixelY(double latitude, byte zoomLevel) { double sinLatitude = Math.sin(latitude * (Math.PI / 180)); long mapSize = getMapSize(zoomLevel); double pixelY = (0.5 - Math.log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * Math.PI)) * mapSize; return Math.min(Math.max(0, pixelY), mapSize); } 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; }