我有一个商店数据库,其中保存了这些商店的坐标。我想获取半径10公里范围内的商店列表,但我不确定如何编写Postgres查询语句,因为我正在使用Postgres数据库。
我的数据库:
我正在尝试将查询添加到SpringBoot地理位置微服务中:
Repository代码:
@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;
}
hibernate-spatial
并安装postgis
。我将会在 spring-boot 中发布一个使用它们的答案。 - Omid