@Transient
public static List<Article> queryByPosition(PositionInfo pinfo){
//System.out.println("------query-----");
//String hql="from Article art where art.author.id="+uid;
double r = 6371;//地球半径千米
double dis = 0.5;//0.5千米距离
double dlng = 2*Math.asin(Math.sin(dis/(2*r))/Math.cos(pinfo.latitude*Math.PI/180));
dlng = dlng*180/Math.PI;//角度转为弧度
double dlat = dis/r;
dlat = dlat*180/Math.PI;
double minlat = pinfo.latitude-dlat;
double maxlat = pinfo.latitude+dlat;
double minlng = pinfo.longitude -dlng;
double maxlng = pinfo.longitude + dlng;
String hql = "from Article art where art.longitude>="+minlng+" and art.longitude <="+maxlng+" and art.latitude>="+minlat+" and art.latitude<="+maxlat+" and art.state=1 ";
if(pinfo.lastId>0){
hql += " and art.id<" + pinfo.lastId;
}
return DbUtil.findListByHql(hql,pinfo.size, Article.class);
}
这样查出数据库中的范围 得到集合