Latitude and longitude coordinates of the andriod front end to query class data in 500M around the database coordinates

Source: Internet
Author: User

@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;//Earth radius km
Double dis = 0.5;//0.5 km distance
Double dlng = 2*math.asin (Math.sin (dis/(2*r))/math.cos (pinfo.latitude*math.pi/180));
DLNG = dlng*180/math.pi;//Angle converted to radians
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);

}

This finds the scope in the database to get the collection

Latitude and longitude coordinates of the andriod front end to query class data in 500M around the database coordinates

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.