Geographical

Mongodb Plugin support geographic characteristics of MongoDB after its version 1.0.8, but only support geo2dsphere index. If you have not added the index yet , I recommend you to add in the code refering to the plugin index section or use the GUI tool, or use the command line to add index at first.

Insert Index in document (only support in version 1.0.8+ of MongoQuery), use setGeo (longitude, latitude)

query.add(new MongoQuery().set("name", "深圳大学").setGeo("geo", 113.9365065988, 22.5350151812));

Show you a example:

MongoQuery query = new MongoQuery().use("point");
MongoGeospatial geo = new MongoGeospatial(113.9365065988, 22.5350151812).circleSphere("geo", 5000.0);
query.geo(geo);
System.out.println(JSON.toJSONString(query.find()));

Firstly create a MongoQuery and write filter conditions such as number , using what collection and so on in it (see searching section)

Then create a new MongoGeospatial object, put into the center of longitude and latitudewhen creating the object and implement a specific strategy.

If you need to declare geographic location in MongoBean, just declaring variable MongoGeospatial (longitude, latitude) and do not follow the strategy:

private  MongoGeospatial localtion=MongoGeospatial(longitude, latitude)

If you want to put multiple points:

MongoQuery query = new MongoQuery().use("point");
MongoGeospatial geo = new MongoGeospatial();
geo.add(longitude, latitude);
geo.add(longitude, latitude);
System.out.println(JSON.toJSONString(query.find()));

Currently supported strategies:

near(String filedName, Double maxDistance, Double minDistance)
nearSphere(String filedName, Double maxDistance, Double minDistance)
circle(String filedName, Double radius)
circleSphere(String filedName, Double radius)

Points in withinPolygon add by “add”.。

withinPolygon(String filedName)

results matching ""

    No results matching ""