Mongodb获取附近的人

来源:互联网 时间:1970-01-01

double[] loc = new double[2];//坐标[longitude, latitude]loc[0] = 114d;//longitudeloc[1] = 118d;// latitudeDBObject near = new BasicDBObject();near.put("$near", loc);//表示near查询,单位是“度”near.put("$maxDistance",  <distance in meters>);//最大距离near.put("$minDistance", <distance in meters>);//最小距离DBObject p = new BasicDBObject();p.put(“loc”, near);//坐标在collection中的字段名,你这是locDBCollection dbCollection = positionDB.getCollection(“places”);//获取数据库里的collection,你这是placesDBCursor dbCursor = dbCollection.find(dbObject).limit(20);//查找20个



相关阅读:
Top