[GIS] Show google coordinates in leafLet with WMS Geoserver

coordinate systemgeoserverleaflet

I am new to GIS and have a problem with using geo-coordinates which I got from Google. I have some lat, lng data in my database(MSSQL) which I obtained from Google API (I think it should be in 3857 format), however, I needed to create a layer in GeoServer, so I created a view as

   geometry::STGeomFromText('Point(' + CAST(dp.lat AS nvarchar(50)) + ' ' + CAST(dp.lng AS nvarchar(50)) + ')', 3857) AS Expr1

In Geoserver, when adding a layer I use the following setting which I believe there is something wrong with it and I am not sure which Compute shall I click and in what order.
enter image description here

In the publishing, I also select point as default style.

and finally in leafLet

 var mywms = L.tileLayer.wms("http://localhost:9090/geoserver/localhost/wms", {
        layers: 'localhost:DP_View',
        format: 'image/png',
        transparent: true,
        version: '1.1.0'
         ,SrsName: 'EPSG:3857'
    });
    mywms.addTo(map);

They either sit in the middle or on top of the map.

Best Answer

I have some lat, lng data which I obtained from Google API (I think it should be in 3857 format)

That's the first source of confusion. EPSG 3857 corresponds to Web Mercator (which uses metres). This is the coordinate reference system used on Google Maps, Leaflet, Bing Maps and ArcGIS.

However, lat/long data corresponds to EPSG 4326 (which uses decimal degrees).

So if your dataset uses lat/long, you should specify EPSG 4326 as the Native SRS in GeoServer.

You can optionally specify the Declared SRS to be EPSG 3857 if you want GeoServer to re-project your data to Web Mercator, but this isn't necessary to use the layer in Leaflet, as Leaflet and GeoServer will work together to perform the conversion on-the-fly.

See https://gis.stackexchange.com/a/48952/3112 for a good explanation of these coordinate systems, and http://docs.geoserver.org/stable/en/user/data/webadmin/layers.html for an explanation of Native vs Declared reference systems.