如何以db.geo.point形式存储用户位置数据到云数据库中?
发布于 4 年前 作者 yang04 8302 次浏览 来自 官方Issues

如何以db.geo.point形式存储用户位置数据到云数据库中?

//选择地址
chooseLocation: function () {
    let that = this;
    wx.chooseLocation({
      success: function (res) {
        console.log(res);
        if (res.address) {
          that.setData({
            address: res.name,
            latitude: res.latitude,
            longitude: res.longitude,
          })
          app.globalData.latitude = res.latitude;
          app.globalData.longitude = res.longitude;
          app.globalData.address = res.address;
          console.log(app.globalData)
        }
      }
    })
  },
//添加地址
addLocation: function () {
    if (!this.data.address) {
      wx.showToast({
        title: '请选择地点!',
        icon: 'none'
      });
      return;
    }
    const location = {
      // type: this.data.locationType,
      time: this.data.time,
      address: this.data.address,
      latitude: this.data.latitude,
      longitude: this.data.longitude
    };
    this.data.loctaions.push(location);
    this.setData({
      loctaions: this.data.loctaions
    });
  },
2 回复

db.geo.point还不够详细的了吗?还需要多解释些什么?

const db = wx.cloud.database()
db.collection('todos').add({
  data: {
    description: 'eat an apple',
    location: db.Geo.Point(res.longitude, res.latitude)
  }
}).then(console.log).catch(console.error)
回到顶部