收藏
回答

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

如何以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 个回答

  • 老张
    老张
    2019-12-25

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

    2019-12-25
    有用
    回复
  • Booker Zhao(赵兵)
    Booker Zhao(赵兵)
    2019-12-25
    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)
    
    2019-12-25
    有用
    回复 4
    • Qiu (吉²)
      Qiu (吉²)
      2019-12-25
      非常感谢🙏。但是会报错。
      2019-12-25
      回复
    • 无亦杨
      无亦杨
      2019-12-25回复Qiu (吉²)
      你的数据库表不存在,需要先建立一个表
      2019-12-25
      回复
    • Qiu (吉²)
      Qiu (吉²)
      2019-12-25回复无亦杨
      嗯嗯,非常感谢🙏
      2019-12-25
      回复
    • 飞天的巨大龟
      飞天的巨大龟
      2020-03-27回复无亦杨
      不懂为何,我用这种方式存不进去。自己构造 才得。type:Point,coordinates:[100,10]这种才行。。。
      2020-03-27
      回复
登录 后发表内容
问题标签