开发者

How to implement Spatial(Geo-Location) searching in Grails?

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:

  1. Search for places with-in a given radius of the user's current co-ordinates
  2. Provide a full text search. We are currently using searchable for this
  3. Do a combination of full text search with-in a given radius of the user's current co-ordinates.

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:

  1. Lucene Spatial Search (http://wiki.apache.org/lucene-java/SpatialSearch) and look into how to use it with searchable

  2. Grails Solr Plugin (http://www.grails.org/plugin/solr). But this does not return domain objects.

  3. 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).

  4. 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 searchab开发者_JAVA技巧le at all.

  5. Postgres/PostGIS integration with hibernate-spatial (http://blog.mollusca.ch/2008/10/4/grails-spatial-data-postgis)

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:

  1. Imagine the circle where radius = max distance
  2. Draw a box around it using the curved longitude lines.
  3. Find items within that box.

In practice this means:

  1. work out how many degrees longitude represent your maximum distance at the given latitude
  2. work out how many degrees latitude represent your maximum distance at the given longitude (this multiplier will be fixed when using a spherical-earth model).
  3. SELECT * FROM places WHERE long > $westside AND long < $eastside AND lat < $northside and lat > $southside

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜