Mongodb获取附近的人

来源:转载

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个



分享给朋友:
您可能感兴趣的文章:
随机阅读: