I have a list of thousands of locations and their Latitude and Longitudes. I need to be able to find all points within, lets say 10 miles, of a user’s lat/long. I was able to do this with the MATH marketplace module. There is a trigonometric formulas that, given two sets of lat/long, will return the distance. So I looped through 1000 or so records, and was able to make a new list of those where the distance between the location and the user’s location was <= 10. I need to be able add this formula to a criteria/filter for retrieving from the database, though. This is a ridesharing app I’m developing for our offices across the country (USA). A user about to drive somewhere should be able to see all users that need rides within 10 miles (for example) from their location. The problem is if there are 1000 requests across the country, I have to retrieve all 1000 requests before I can trim it down to the 5-10 that are within 10 miles. The MATH module is great for this, but because of the extra processing I need to do, its going to be REALLY slow. it would be nice to just use my formula inside some kind of criteria expression but it involves trig formulas such as radians, cosine, etc. There’s no way to get around this, is there? Is there any special RETRIEVE module that has advanced math formulas built int?
You could maybe improve performance like this:
Retrieve locations from your database where compared to your user’s location longitude difference < x and latitude difference < y to get results that are within an imaginary box of < ~12 miles around your user’s location on the map. The x value per mile depends on your latitude, but you should be able to use a hard value that covers the USA locations.
Then you could loop through the results and use a java action to check which are within a circle of 10 miles around the user’s location, calculating the distance between geo locations like suggested here. Closest then means “as the bird flies” btw, not driving distance or anything like that.
This way you don’t have to loop over all of your locations, only a subset that you retrieved first based on longitude and latitude difference.