我使用的是Play Frameworkv1.2.5和连接到MongoDB v2.4.5的PlayMorphia吗啡模块PlayMorphia v1.2.12。
我不知道如何使用Mor体进行地理空间查询。
例如,基本查询很好:
//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");但是,文献资料没有提到如何使用MongoDB的$geoWithin $geoIntersects $near $nearSphere查询。
正如文档中所暗示的那样,我尝试使用类似的东西,但是它没有起作用。
List<Address> e = Address.q().filter("latlon near","[47.5, -122.3]").asList();发布于 2013-09-19 22:02:19
我找到了一种方法来实现这一点,然而,这是相当丑陋的,因为结果需要铸造。
List<Address> addresses = (List<Address>)(List<?>) Address.q().field("latlon").near(47.5, -122.3).asList();发布于 2013-09-19 21:45:42
我认为最终的问题是,要筛选的参数是字符串,而不是double[]。尝试类似于: Address.q().field("latlon").near(47.5,-122.3)。如果您特别需要$geoWithin,可以使用.field("latlon").within(Shape.center(new (47.5,-122.3),someRadius)。对于within()的那个版本,您将需要morphia 0.104。
https://stackoverflow.com/questions/18905139
复制相似问题