I am working on Grails 1.3.2 with MySql. I need to store the latitude and longitude of certain locations in the database and then on the basis of the user's current location, I need to return the items that are within a particular radius of that location. So, we basically have the following requirements:
I have been looking into the various options that we have here and wanted to know what are your views/ suggestions to implement this. The various options that we have here are:
Lucene Spatial Search (http://wiki.apache.org/lucene-java/SpatialSearch) and look into how to use it with searchable
Grails Solr Plugin (http://www.grails.org/plugin/solr). But this does not return domain objects.
Grails Stitches Plugin (http://www.grails.org/plugin/stitches). There is not a lot of documentation except on the author's site (http://www.philliprhodes.com/content/stitches-30-seconds).
MySql spatial extension along with a full text index on all the fields of the domain class. If we go this route, then we will not be using searchable at all.
I believe that this is a very basic requirement in any application that integrates with maps.
So, I am really interested in knowing the most appropriate way to implement this functionality.
Thanks
(I made a prototype using Long/Lat to find rows within a radius, but have now abandoned that in favour of the GridRef system available in the UK)
As a first step, don't use a WHERE condition based on a calculated field (e.g. actual distance based on the given coord and the row's coord).
Instead, try this:
In practice this means:
This means you do very simple calculations to get a vague subset covering an area about 30% larger than your actual circle. If you want to add a text search too, either SELECT FROM (subquery) or add your text clause AFTER the simple comparison above, as text searches are computationally expensive.
There is a Grails Spatial plugin. Looks like SOME of its subplugins do support searching, like HDB plugin.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With