如何解决使用 Sequelize 进行地理编码
我希望每当我通过在 sequelize 中使用 Post 请求添加地址时,该地址在存储到我的 MariaDB 服务器之前使用地理编码进行转换。
我的模型目前是这个
const moment = require("moment");
module.exports = (sequelize,DataTypes) => {
return sequelize.define(
"Event",{
id: {
type: DataTypes.UUID,defaultValue: DataTypes.UUIDV1,primaryKey: true,},title: {
type: DataTypes.STRING,allowNull: false,description: {
type: DataTypes.STRING,allowNull: true,date_event: {
type: DataTypes.DATE,get: function () {
return moment(this.getDataValue("date_event"))
.locale("fr")
.calendar(null,{
sameDay: function (now) {
if (this.isBefore(now)) {
return "[Commencé à] HH:mm [aujourd'hui]";
} else {
return "[A] HH:mm [aujourd'hui]";
}
},nextDay: "[Demain] à HH:mm",lastDay: "[Terminé hier] à HH:mm",lastWeek: "[Terminé] dddd [dernier] ",sameElse: "ddd Do MMM YYYY,à HH:mm",});
},location: {
allowNull: false,type: DataTypes.STRING,latitude: {
allowNull: true,type: DataTypes.DECIMAL
},longitude: {
allowNull: true,image: {
allowNull: true,{
timestamps: true,createdAt: "created",}
);
};
我希望根据使用地理编码输入的位置自动填充我的纬度和经度字段。我知道我可以使用 Google Api,但不确定如何使用。
我该怎么做?
谢谢
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。