Search code examples
baqend

What is the correct syntax for saving a GeoPoint in Baqend?


What is the correct syntax for saving latitude and longitude in Baqend?

I am successfully saving the normal fields (all of them are strings):

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

But I can't seem to get the geo to save correctly. Probably because I'm treating it as a string and that is not correct?

In the example code I'm just hardcoding it now to values I know are good so we can get this working.


Solution

  • I think the answer here is that the sdk provides a function that encodes it correctly:

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