I have a database of shops and in that database I have coordinates for these shops saved. I would like to get the list of shops in a 10km radius however I am not sure how to write the Postgres query since I am using Postgres database.
My database :
I am trying to add the query to a springboot geolocation microservice :
Repository code :
@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);
}
SellerObject :
@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;
}