1

在 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
         })
      })
    }

但我似乎无法正确保存地理信息。可能是因为我将它视为一个字符串,这是不正确的?

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

4

1 回答 1

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
         })
      })
    }
于 2017-09-26T16:42:53.280 回答