Trigonometric functions in Xpath constraints

I have a LOCATION entity with hundreds of records that all have Latitude and Longitude decimal attributes.   I want to be able to get all LOCATIONS within X kilometers of the user (the user also has a Lat/Long coordinate set). The user changes X in a parent entity that is used for filtering.   I found the MATH module that lets me use a trig function to get the distance between two lat/ong coordinates and it works perfectly.   Distance = (acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(lon2-lon1))*6371) * (pi/180)   So I COULD loop through every single LOCATION value and then return a list of all the values less than/equal to X.   BUT… I want to know if there’s a way to do this inside of a constraint… that way to I dont have to loop through what could be hundreds, even thousands of records. Does anyone know if Xpath has any trig abilities or if there is something LIKE that MATH module but lets you apply it to some sort of retrieve action?     
1 answers

This is a complex task to handle.

I’ve done this in the past with a java action by finding the points within a distance of a lat/long using binding coordinates as described here:

This could be a starting point as the java code that you’d need is available from that page.

Hope this helps.