0

在这里,我有商店和用户的纬度和经度,我想在用户和商店的纬度和经度之间显示我的商店清单。我如何在 sequlize orm 中做到这一点

 const latitude = req.query.latitude; // user latitude 
 const longitude = req.query.longitude; // user longitutde 

 const shopLists = await Shop.findAll({
            limit,offset,
            attributes:["latitude","longitude"],
            where:{
                category_id:category_id,
                status:1,
            },
            include :{
                model:Category,attributes:['id','name']
            }
        });

4

1 回答 1

0
const limit;
// what is offset?
const shopLists = await Shop.findAll({
    where: {
        longitude: {
            [Op.ne]: null,
        },
        latitude: {
            [Op.ne]: null,
        },
        [Op.and]: [
            Sequelize.where(
                Sequelize.fn(
                    'ST_Distance',
                    Sequelize.fn('point', Sequelize.col('longitude'), Sequelize.col('latitude')),
                    Sequelize.fn('point', longitude, latitude),
                ),
                '<',
                limit,
            ),
        ],
    },
})

于 2021-08-18T12:07:14.407 回答