select
l.id,
l.name,
l.address,
ST_Y(l.point::geometry) as lat,
ST_X(l.point::geometry) as long,
ST_Distance(
l.point,
ST_SetSRID(ST_MakePoint(user_long, user_lat), 4326)::geography
) as dist_meters
from gis.locations l
where ST_DWithin(
l.point,
ST_SetSRID(ST_MakePoint(user_long, user_lat), 4326)::geography,
radius_meters
)
order by dist_meters;
select
l.id,
l.name,
l.address,
ST_Y(l.point::geometry) as lat,
ST_X(l.point::geometry) as long,
ST_Distance(
l.point,
ST_SetSRID(ST_MakePoint(user_long, user_lat), 4326)::geography
) as dist_meters
from gis.locations l
where ST_DWithin(
l.point,
ST_SetSRID(ST_MakePoint(user_long, user_lat), 4326)::geography,
radius_meters
)
order by dist_meters;