利用MongoDB实现地理空间索引与数据库扩展
地理空间索引基础
在处理地理空间数据时,我们常常需要将地址转换为经纬度坐标。可以使用像Google、Yahoo!、Bing等提供的地图API来实现这一转换,这一过程被称为地理编码。在Ruby中,有许多可用的gem来完成地理编码,其中 geocoder 是一个不错的选择。
使用geocoder存储坐标的步骤 :
1. 在 Gemfile 中添加 geocoder :
gem 'geocoder'
- 更新
Address模型:
class Address
include Mongoid::Document
include Geocoder::Model::Mongoid
field :street, type: String
field :zip, type: Integer
field :city, type: String
field :state, type: String
field :country, type: String
field :coordinates, type: Array
belongs_to :location, polymorphic: true
geocoded_by :forma
超级会员免费看
订阅专栏 解锁全文
39

被折叠的 条评论
为什么被折叠?



