convertFromWebMercator function
Converts Web Mercator EPSG:3857 coordinates to decimal latitude and longitude.
The function takes in the x
and y
coordinates in the Web Mercator EPSG:3857
projection and converts them to decimal degrees for latitude and longitude.
x
: The x-coordinate in Web Mercator EPSG:3857.y
: The y-coordinate in Web Mercator EPSG:3857.
Returns a list of two double values representing the converted decimal latitude and longitude. The first value is the converted longitude, and the second value is the converted latitude.
Implementation
List<double> convertFromWebMercator(double x, double y) {
final longitude = (x / 20037508.34) * 180.0;
final lat0 = (y / 20037508.34) * 180.0;
final radiansToDegrees = 180.0 / pi;
final latitude =
radiansToDegrees * (2.0 * atan(exp(lat0 / radiansToDegrees)) - pi / 2.0);
return [longitude, latitude];
}