В итоге я использовал необработанный SQL-запрос с gis:
var query = req.query;
var latitude = parseFloat(query.latitude);
var longitude = parseFloat(query.longitude);
var limit = query.limit || 10;
const maxDistance = parseFloat(query.maxDistance) || 10000;
models.sequelize.query('SELECT "id", "origin", "radius", "createdAt", "updatedAt", "regionID", ST_Distance("origin", ST_MakePoint(?, ?), false) AS "distance" FROM "regions" AS "region" WHERE ST_DWithin("origin", ST_MakePoint(?, ?), ?, false) = true AND ST_Distance("origin", ST_MakePoint(?, ?), false) - radius <= 0 ORDER BY distance ASC LIMIT ?;', { replacements: [latitude, longitude, latitude, longitude, maxDistance, latitude, longitude, limit], type: models.sequelize.QueryTypes.SELECT, model: models.Region }).then( regions => {
return res.json(regions);
});
Вот лучше отформатированный (псевдо) оператор SQL:
SELECT *
FROM regions
WHERE ST_DWithin("origin", ST_MakePoint(lat, long), max, false) = true AND ST_Distance("origin", ST_MakePoint(lat, long), false) - radius <= 0
ORDER BY distance ASC
LIMIT 5;