你如何使用共享数据库在Heroku上进行GIS查询?

我有一张经纬度地理位置的经纬度表。 我希望我的数据库查询返回它们的过滤列表,按固定点的距离排序。

我探索过几个选项:

  • Postgresql的earthdistance contrib可能最接近我的需求; 但是,我没有发现这是在heroku的数据库服务器上安装的迹象。
  • PostGIS是最常用的GIS解决方案,但heroku没有安装它,heroku支持证实他们不打算在不久的将来这样做。

我需要一个适用于Rails3的解决方案。

如果没有更好的选择,我将不得不实现我自己的hasrsinefunction,这肯定似乎重新发明轮子。 有更好的选择吗?

我现在(2011年7月)建议使用地理编码器

gem 'geocoder' 

http://www.rubygeocoder.com/

您也可以像我之前提到的那样使用geokit-rails3,但它不完整且无法维护。

 gem 'geokit-rails3' 

http://github.com/jlecour/geokit-rails3

Geokit将在数据库中使用hasrsine处理所有距离计算。 它也适用于heroku和postgres。 极力推荐。

Geokit Gem Rails Geokit集成

所有代码都来自github

 class Location < ActiveRecord::Base acts_as_mappable :default_units => :miles, :default_formula => :sphere, :distance_field_name => :distance, :lat_column_name => :lat, :lng_column_name => :lng end Store.find :all, :bounds=>[sw_point,ne_point] bounds=Bounds.from_point_and_radius(home,5) stores=Store.find :all, :include=>[:reviews,:cities] :bounds=>bounds stores.sort_by_distance_from(home) 

Postgis目前处于测试版(2012年3月) https://addons.heroku.com/spacialdb

Heroku现在(2013年2月)对PostGIS有beta级支持。 其详细信息可在其网站上找到(需要登录): https : //devcenter.heroku.com/articles/heroku-postgres-extensions-postgis-full-text-search#postgis

PostGIS的:

将地理对象的支持添加到PostgreSQL对象关系数据库。 实际上,PostGIS“空间支持”PostgreSQL服务器,允许它用作地理信息系统(GIS)的后端空间数据库

Heroku Postgres上的PostGIS v1.5支持处于测试阶段,未来可能会发生变化。