正在从sql查询结果中删除[TextRow]



所以我正在使用mysql数据库来保存位置的纬度和经度,我的查询结果如下:

[ TextRow { platitude: '34.19226000', plongitude: '-118.53556100' } ],

我想去掉[TextRow],只需要将数组存储在一个变量中,以通过Geolib函数。

我目前将纬度和经度作为小数存储在我的数据库中

platitude : {
type : DataTypes.DECIMAL(10,8),
},
plongitude : {
type : DataTypes.DECIMAL(11,8)
},

我的目标是在查询结果中使用findNeast-Geolib函数

这就是我目前拥有的:

const query = sequelize.query("SELECT platitude,plongitude FROM peachyPatient.registeredPractices where practiceID ='1'").then(
function(result){
const practices = result;
const location = geolib.findNearest({ latitude: 52.456221, longitude: 12.63128, }, [
practices,
{ latitude: 51.503333, longitude: -0.119722 },
{ latitude: 55.751667, longitude: 37.617778 },
{ latitude: 48.8583, longitude: 2.2945 },
{ latitude: 59.3275, longitude: 18.0675 },
{ latitude: 59.916911, longitude: 10.727567 },
// { latitude: 52.516272, longitude: 13.377722 },

]); console.log(location);
}
);

当我console.log位置时,它只是简单地返回我的查询结果。

这就是文档中geoLib函数的样子

geolib.findNearest({ latitude: 52.456221, longitude: 12.63128 }, [
{ latitude: 52.516272, longitude: 13.377722 },
{ latitude: 51.515, longitude: 7.453619 },
{ latitude: 51.503333, longitude: -0.119722 },
{ latitude: 55.751667, longitude: 37.617778 },
{ latitude: 48.8583, longitude: 2.2945 },
{ latitude: 59.3275, longitude: 18.0675 },
{ latitude: 59.916911, longitude: 10.727567 },
]);

如有任何关于如何解决这一问题的帮助,我们将不胜感激。

试试这个:它应该返回不带TextRow的对象的纯json数组。

var resultArray = Object.values(JSON.parse(JSON.stringify(result)))

最新更新