Convert coordinates from EPSG-4326 to EPSG-3857
To convert coordinates from EPSG:4326 (WGS84 - latitude/longitude) to EPSG:3857 (Web Mercator projection) in JavaScript, you can use the following formula. This converts latitude and longitude into X and Y coordinates suitable for map display (such as Google Maps or OpenStreetMap).
Formula for Conversion:
Explanation:
-
RADIUS
is the Earth's radius in meters for the Web Mercator projection. -
Longitude is converted to the X coordinate by multiplying the longitude (in degrees) by the radius and converting it to radians.
-
Latitude is converted to the Y coordinate using the Mercator projection formula, which involves logarithms and trigonometric functions.
This conversion is necessary for displaying geographic coordinates on web-based mapping systems that use the EPSG:3857 projection.