convertToWebMercator function

List<double> convertToWebMercator(
  1. double longitude,
  2. double latitude
)

Converts latitude and longitude coordinates in decimal degrees to the Web Mercator EPSG:3857 coordinate system.

The Web Mercator projection is commonly used in web mapping applications. The conversion formula scales and transforms the latitude and longitude coordinates to match the coordinate system used by Web Mercator.

  • longitude: The longitude coordinate in decimal degrees.
  • latitude: The latitude coordinate in decimal degrees.

Returns a list of two double values representing the converted coordinates in the Web Mercator EPSG:3857 coordinate system. The first value is the converted longitude (x) and the second value is the converted latitude (y).

Implementation

List<double> convertToWebMercator(double longitude, double latitude) {
  final x = longitude * 20037508.34 / 180.0;
  var y = log(tan((90.0 + latitude) * pi / 360.0)) / (pi / 180.0);
  y = y * 20037508.34 / 180.0;

  return [x, y];
}