I am trying to make a query (using raw query in sequelize orm for a PostgreSQL with PostGIS database) for a radius of a certain 'maxDistance' radius (preferably in meters):
const maxDistance = 100000000
const lat = 4.307662331310191
const lon = 52.09468958820517
const sequelize = hook.app.get('sequelizeClient')
return sequelize.query(`SELECT "id", "created_at", "wkb_geometry", ST_Distance(ST_SetSRID(ST_MakePoint(${parseFloat(lat)}, ${parseFloat(lon)}), 3857), "wkb_geometry") AS distance FROM "points" WHERE ST_Distance(ST_SetSRID(ST_MakePoint(${parseFloat(lat)}, ${parseFloat(lon)}), 3857), "wkb_geometry") < ${maxDistance}`)
When I create another point, i.e.: const HOME_LONLAT = [4.295980701608052, 52.09069818826458]
in the database and run the query I get a result with a distance of 0.012344705180102
however the actual distance of these two geopoints is approx 930 meters. What am I doing wrong or how should I convert the distance to get the distance in meters?
EDIT: When I alter the query into:
'SELECT "id", "created_at", "wkb_geometry", ST_Distance(ST_GeogFromText(\'SRID=3857;POINT(4.307662331310191 52.09468958820517)\'), "wkb_geometry") AS distance FROM "points" WHERE ST_Distance(ST_GeogFromText(\'SRID=3857;POINT(4.307662331310191 52.09468958820517)\'), "wkb_geometry") < 100000000'
I get this error:
error: Only lon/lat coordinate systems are supported in geography
EDIT2: In PostGIS I have 3857 CRS:
SELECT ST_SRID("wkb_geometry") FROM points;
st_srid
---------
3857