Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java PlayMorphia地理空间查询_Java_Mongodb_Geospatial_Playframework 1.x_Morphia - Fatal编程技术网

Java PlayMorphia地理空间查询

Java PlayMorphia地理空间查询,java,mongodb,geospatial,playframework-1.x,morphia,Java,Mongodb,Geospatial,Playframework 1.x,Morphia,我正在使用Play Framework v1.2.5和MongoDB Morphia模块PlayMorphia v1.2.12连接到MongoDB v2.4.5 我不知道如何使用Morphia进行地理空间查询 例如,基本查询可以: //save a test address new Address(47.5, -122.3, "123 South Main Street", "Seattle", "WA", "98109").save(); //now find it List<Addr

我正在使用Play Framework v1.2.5和MongoDB Morphia模块PlayMorphia v1.2.12连接到MongoDB v2.4.5

我不知道如何使用Morphia进行地理空间查询

例如,基本查询可以:

//save a test address
new Address(47.5, -122.3, "123 South Main Street", "Seattle", "WA", "98109").save();

//now find it
List<Address> address = Address.q().filter("city", "Seattle").filter("street", "123 South Main Street").asList();
assertEquals(address.get(0).street,"123 South Main Street");
//保存测试地址
新地址(47.5,-122.3,“西雅图南大街123号”,“华盛顿州”,“98109”)。保存();
//现在找到它
这个列表并没有提到如何使用MongoDB的$geoIntersects$near$nearSphere查询

正如文档中所暗示的那样,我尝试过使用类似的东西,但没有成功

List<Address> e = Address.q().filter("latlon near","[47.5, -122.3]").asList();
List e=Address.q().filter(“latlon near”,“[47.5,-122.3]”)asList();

我认为最终的问题是要筛选的参数是字符串而不是双精度[]。尝试类似于:Address.q().field(“latlon”).near(47.5,-122.3)。如果您特别想要$GEOIN,您可以使用.field(“latlon”).within(Shape.center(new Point(47.5,-122.3),someRadius)。该版本的within()需要morphia 0.104。

我找到了一种方法来实现这一点,但是,它非常难看,因为结果需要浇铸

List<Address> addresses = (List<Address>)(List<?>) Address.q().field("latlon").near(47.5, -122.3).asList();
List addresses=(List)(List)Address.q().field(“latlon”).near(47.5,-122.3).asList();

谢谢。使用Address.q().field(“latlon”).near(47.5,-122.3)确实有效-但是,它返回了超级类(Model),这需要一些难看的铸造。哦,这是Java!一定是玩morphia的东西。morphia应该只是返回列表。我猜是Address.q()类型不正确。我不确定您是否需要强制转换到列表。当然,该列表是不必要的。asList()已经返回了一个列表,因此只要您的查询类型正确,返回类型应该已经是List