[英]HQL : Distance calculation between two locations?
I have a table Restaurants
which stores the details of restaurants including Latitude
and Longitude
.now i have to sort out the records from DB those within 20 Kilo Meter
of the given Lat/Lon
input values. 我有一个表格
Restaurants
,其中存储了饭店的详细信息,包括Latitude
和Longitude
现在,我必须从数据库中整理出给定Lat/Lon
输入值在20 Kilo Meter
公里以内的那些记录。
I am using RESTful web-service with hibernate. 我正在将RESTful Web服务与hibernate一起使用。
Entity Class 实体类别
@Entity
@Table(name = "restaurants")
public class Restaurants implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "restaurant_id")
private int restaurantId;
@Column(name = "restaurant_name")
private String restaurantName;
@Column(name = "category_id")
private Integer categoryId;
@Column(name = "image_url")
private String imageUrl;
private Float longitude;
private Float latitude;
@Column(name = "contact_name")
private String contactName;
@Column(name = "primary_phone")
private String primaryPhone;
@Column(name = "secondary_phone")
private String secondaryPhone;
private String fax;
private String address1;
private String address2;
//Getters and Setters
}
I have surfed but couldn't find any satisfying answer.is it preferable between
operation to find out the difference between Lat/Long
.or do i use Criteria
? 我已经冲浪了,但是找不到满意的答案。是否最好
between
两次操作between
找出Lat/Long
之间的差异。还是使用Criteria
? Any one please provide me an answer .? 有人可以给我一个答案吗?
Maybe you choose use Hibernate Spatial ? 也许您选择使用Hibernate Spatial?
You can find a tutorial here: http://www.hibernatespatial.org/documentation/02-Tutorial/01-tutorial4/ 您可以在此处找到教程: http : //www.hibernatespatial.org/documentation/02-Tutorial/01-tutorial4/
Becareful all database doesn't support Hibernate Spatial. 请注意,所有数据库均不支持Hibernate Spatial。 You can check your database support here: http://www.hibernatespatial.org/documentation/03-dialects/01-overview/
您可以在此处检查数据库支持: http : //www.hibernatespatial.org/documentation/03-dialects/01-overview/
Also becareful to change your SQLDialect 还要小心更改您的SQLDialect
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.