I'm trying to overlay tiles from a WMS server (a map of the ocean biomass) on a Google Map (android), but the projection is slightly distorted.
As you can see in this picture, the longitudes are OK, but the latitudes get distorted the farther away from the equator you get:
When zooming in, the distortion is no longer visible:
The WMS accepts EPSG:4326 bounding boxes (I've reviewed other questions on this topic, but they all use a WMS that accepts different coordinate systems).
I'm calculating the WMS BBOX coordinates out of the (x,y,zoom) parameters in getTile by calling tile2boundingBox(x,y,zoom)
(calculation taken from https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames):
double tile2lon(int x, int z) {
return x / pow(2.0, z) * 360.0 - 180;
}
double tile2lat(int y, int z) {
double n = pi - (2.0 * pi * y) / pow(2.0, z);
return vector_math.degrees(atan(sinh(n)));
}
tile2boundingBox(final int x, final int y, final int zoom) async {
final north = tile2lat(y, zoom);
final south = tile2lat(y + 1, zoom);
final west = tile2lon(x, zoom);
final east = tile2lon(x + 1, zoom);
return [south, west, north, east];
}
And then I create a WMS url to fetch the tile with the BBOX e.g:
I've also compared my calculation to the python program in MapTiler: https://www.maptiler.com/google-maps-coordinates-tile-bounds-projection/ and the coordinated are exactly the same:
What am I doing wrong?