在Baqend中保存GeoPoint的正确语法是什么?

时间:2017-09-26 16:35:52

标签: baqend

在Baqend中保存纬度和经度的正确语法是什么?

我成功保存了正常字段(所有这些都是字符串):

  handleSubmit(event) {
      event.preventDefault();
      var newcompany  = new db.Companies({
        name: this.state.name,
        photo: '',
        geo: '47.626814;-122.357345',        
        address1: this.state.address1,
        address2: this.state.address2,
        city: this.state.city,
        state: this.state.state,
        zip: this.state.zip,
      });

      newcompany.insert().then(() => {
        //console.log(newcompany)
        this.setState({
          redirect: true,
          newcompanykey: newcompany.key
         })
      })
    }

但我似乎无法正确保存地理位置。可能是因为我把它当作字符串来处理并且这是不正确的?

在示例代码中,我现在只是将其硬编码为我知道的值,因此我们可以使其正常工作。

1 个答案:

答案 0 :(得分:1)

我认为这里的答案是sdk提供了一个正确编码它的函数:

handleSubmit(event) {
      event.preventDefault();
      var geo = new db.GeoPoint(47.626814, -122.357345)
      var newcompany  = new db.Companies({
        name: this.state.name,
        photo: '',
        geo: geo,
        address1: this.state.address1,
        address2: this.state.address2,
        city: this.state.city,
        state: this.state.state,
        zip: this.state.zip,
      });

      newcompany.insert().then(() => {
        //console.log(newcompany)
        this.setState({
          redirect: true,
          newcompanykey: newcompany.key
         })
      })
    }