【发布时间】:2019-11-29 20:29:04
【问题描述】:
我有一个商店数据库,在该数据库中我保存了这些商店的坐标。我想获取半径 10 公里内的商店列表,但是我不知道如何编写 Postgres 查询,因为我使用的是 Postgres 数据库。
我的数据库:
我正在尝试将查询添加到 springboot 地理定位微服务:
存储库代码:
@Repository
public interface SellerGeolocationRepository extends CrudRepository<Seller_Geolocation, Long> {
@Query(value="SELECT * FROM seller_geolocation_ms WHERE
// get coordinates that are in the vicinity
", nativeQuery = true)
public Set<Seller_Geolocation> findAllSellersInRange(double longitude, double latitude);
}
卖家对象:
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "seller_geolocation_ms")
public class Seller_Geolocation {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private static final long serialVersionUID = 2L;
private double latitude;
private double longitude;
private String country;
private String city;
private String zipCode;
private String town;
private String address;
private Long sellerId;
}
【问题讨论】:
-
@Erent 为什么不使用像
com.vividsolutions.jts.geom.Point这样的类来保存地理空间数据,而不是简单地保存两个双数字?在这种情况下,您可以轻松地进行地理空间查询 -
我不知道 com.vividsolutions.jts.geom.Point,如果我要使用它,我将如何进行查询
-
您需要使用
hibernate-spatial并安装postgis。我将在 spring-boot 中使用这些发布答案 -
@Erent 看看这个question 这就是你应该如何实现它。
标签: java postgresql spring-boot geolocation