因此,我正在使用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 },
]);
任何关于如何澄清这一点的帮助都将不胜感激。
发布于 2021-03-30 03:47:49
试试这个:它应该返回对象的普通json数组,不带TextRow。
var resultArray = Object.values(JSON.parse(JSON.stringify(result)))
https://stackoverflow.com/questions/65415875
复制相似问题