使用 Java 重新思考 Db 地理空间查询返回不正确的值



我正在尝试使用java进行一个简单的RethinkDb查询,涉及r.point方法。乍一看,它似乎工作正常。但是,使用 reql 语法直接从终端执行此方法将返回完全不同的值。谁能理解为什么会这样?或者,如果它们代表相同的地理空间坐标?

这是我使用的代码:

    Point geoloc = RethinkDB.r.point(Float.parseFloat(parsedLocation[0]),Float.parseFloat(parsedLocation[1]));
    data.setGeolocation(geoloc);
    db = new Db();
    int reponse = db.putDataInCollection(data); //Simply put the object in the database

这将为地理位置字段返回以下内容:

"geolocation": {
  "args": [
      {
      "args": [ ],
      "datum": -122 ,
      "optargs": { } ,
      "termType":  "DATUM"
      } ,
      {
      "args": [ ],
      "datum": 88 ,
      "optargs": { } ,
      "termType":  "DATUM"
      }
   ], 
   "optargs": { } ,
   "termType":  "POINT"
   } 

但是,从终端执行完全相同的命令返回:

"geolocation": {
   "$reql_type$":  "GEOMETRY" ,
   "coordinates": [
       -122.2 ,
       74.8
       ] ,
   "type":  "Point"
 }

这绝对不是一回事。

我做错了什么?

编辑:尝试使用Javascript执行相同的方法,它工作得很好。然而,在java中似乎有些不对劲。

到今天我还没有找到问题的原因,但是前段时间我设法提出了一个替代解决方案,如果有人遇到同样的问题,就在这里:

包装 com.unwheeze.beans;

public class GeoBean {
    private String $reql_type$;
    private double coordinates[];
    private String type;

    public GeoBean() {}
    public GeoBean(double[] coordinates) {
        this.$reql_type$ = "GEOMETRY";
        this.coordinates = coordinates;
        this.type = "POINT";
    }
    public String get$reql_type$() {
        return $reql_type$;
    }
    public void set$reql_type$(String $reql_type$) {
        this.$reql_type$ = $reql_type$;
    }
    public double[] getCoordinates() {
        return coordinates;
    }
    public void setCoordinates(double[] coordinates) {
        this.coordinates = coordinates;
    }
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
}

我在 rethinkDB 中创建了一个简单的 bean,重现了 REAL geoJson 字段的字段,我只是在将整个 Json 对象推送到数据库之前使用 Gson 解析它。

最新更新