I'm have entities with latitude and longitude and I would like to select those nearest to a given point.
I found this example that looks like it would work
SELECT *,
SQRT(POW((69.1 * (locations.latitude - 27.950898)) , 2 ) +
POW((53 * (locations.longitude - -82.461517)), 2)) AS distance
FROM locations
ORDER BY distance ASC
LIMIT 5
But I would prefer to do it with JPQL since I have a bunch of other joins etc that feels easier to do in JPQL instead of native query.
When I try something like this the JPA is complaining about the SQRT token.
SELECT DISTINCT p, SQRT(....) AS distance, FROM Place p .... ORDER BY distance ASC
Anyone has knows how to write a query like this, or maybe another better approach?
Thanks! /Oskar