【发布时间】:2017-11-24 07:55:21
【问题描述】:
我在 Sequelize 中有一个位置模型
var Sequelize = require('sequelize');
module.exports = function(sequelize, DataTypes) {
var Location = sequelize.define('Location', {
location_id: {
type: Sequelize.STRING,
primaryKey: true
},
location_code: {
type: Sequelize.STRING,
allowNull: true
},
location_name: {
type: Sequelize.STRING,
allowNull: true
},
latitude: {
type: Sequelize.STRING,
allowNull: true,
defaultValue: null
},
longitude: {
type: Sequelize.STRING,
allowNull: true,
defaultValue: null
},
location: {
type: Sequelize.GEOMETRY('POINT'),
allowNull: true
}
});
return Location;
};
我通过喂食将纬度和经度插入位置
var location = { type: 'Point', coordinates: [latitude, longitude] };
我有一个以纬度和经度为参数的路由器。我需要找出提供的纬度/经度与位置表中所有位置之间的距离。
我该怎么做呢? Sequelize 是否已经为我提供了查找距离的功能,还是我需要编写外部查询才能找到它?
谢谢。
【问题讨论】:
-
会使用一定的距离还是需要按距离排序?
-
你可以在这里找到答案:stackoverflow.com/a/46438100/2363703
标签: mysql sequelize.js geospatial latitude-longitude