开发者

Storing longitude and latitude data in a database, and query for nearby records

I am creating a rails application which will use geolocation. One can add a longi- and latitude to a record. If there are multiple records with geolocations, one can see a Google Map with nearby records, just like Twitter geolocation.

How can I store the coordinates (I don't mind to do calculations) and fin开发者_Python百科d nearby records? My database is MySQL.

Thanks.


There are two approaches you could take, depending on your requirements:

  • Store the co-ordinates yourself (as you had planned). You should check out the Geokit gem which supports a MySQL backend and provides helpers for finding nearby locations.
  • Store your co-ords with with Simplegeo for which you can use this gem. Again, this takes care of your storage and finding nearby.


Geokit is OK for data after it is pulled from a database, but not if you are looking to structure a query from the database using spatial data. If you were only using mysql then you would be kind of stuck doing alot of calculations. Since you are using rails, you have at least this option: http://freelancing-god.github.com/ts/en/geosearching.html which should take care of a great deal of the calculations for you.


You can use acts_as_solr_reloaded to index and query your spatial data for this you need not to store latitude and longitude information in your main table but rather it creates a migration which creates a locals table where it stores the latitude and longitude information.And you can query the solr indexes using this also with latitude,longitude and radius.


Have a look at Geokit. It is widely used in map-based applications.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜