[GIS] Convert from WGS84 to Google Mercator

convertcoordinate systemjavascriptopenstreetmap

I want to convert longitude and latitude coordinates from WSG84 to Google Mercator. The following code-samples show my coordinates in a KML/KMZ file and where I need the coordinates in the javascript file.

<LatLonBox>
   <north>50.0</north>
   <south>46.0</south>
   <east>18.0</east>
   <west>13.0</west>
</LatLonBox>


new ol.layer.Image({
            source: new ol.source.ImageStatic({
                url: 'file:///C:/Users/Xhy/Desktop/cubic.png',
                imageExtent:[1447153.38031, 5780349.22026, 2003750.83428, 6446275.84102]
            })
        })

I am currently using this site here to convert my coordinates from WSG84 to Google Mercator.

I need to automate these conversion, since I have to create OSM-files with different image layers. I have the latitude and longitude in a KML/KMZ file, I can read out of it, and use the coordinates.

My problem is, these coordinates I extract from the KML/KMZ files are WSG84 but for java-script I need the coordinates in Google Mercator.

Any ideas how I can make this conversion inside the javascript file?

Best Answer

I'm not familiar with programming in JavaScript but in the OpenStreetMap Wiki there is a section describing "Mercator". Following this link you'll find a sample code snippet to tranform from lat long to mercator. I actually don't know if it's correct because I did not test the code.