خرید بک لینک

Vote count: 0

I have latitude and longitude in my Location enitity. Now im using something like that to get nearest locations by given coords.

String haversine = "(3956 * 2 * ASIN(SQRT(" +
        "POWER(SIN((l.latitude - ?1) *  pi()/180 / 2), 2) +" +
        "COS(l.latitude * pi()/180) * COS(?1 * pi()/180) *" +
        "POWER(SIN((l.longitude - ?2) * pi()/180 / 2), 2) )))";

@Query(value = "SELECT l FROM Location l ORDER BY " + haversine)
List<Location> findNearest(String latitude, String longitude);

But now I want to customize this query with Query DSL. I'm trying to find out how to sort records by given formula and values from entity, using OrderSpecifier<?>

Maybe I should create method in my Location entity which retus me distance between place and given coords. But I think creating method in MODEL layer is not the best approach for this problem.

So my main question is: how to sort records by given formula (eg Haversine) in Query DSL

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: شنبه 8 خرداد 1395 ساعت: 7:57

صفحه بندی