Geolocalização com
mongoDB e Rails
e outros nosql em startups




 Maurício Maia               @mauricio
vitrines de produtos
cache de produtos
mongoDB > MySQL > Cassandra
Yahoo! Open Hack Day
março 2010
PlaceHacker
Sinatra, MongoDB, mongo-ruby-driver
Topical
PlaceHacker rewrite


 Rails 3
 MongoDB
 Mongoid
 Reconhecimento de Entidades
Topical
Mapa de notícias
Topical
Stream de notícias locais
Topical
Mobile
Por que mongoDB?

fácil
flexível
cases
geospatial indexing
Cases
analytics, real-time, documentos, geo-location
Show me the code!
Preparando
$ gem install mongoid --pre
$ gem install bson_ext


Gemfile
gem "mongoid", "2.0.0.beta.16"
gem "bson_ext", "1.0...
Geospatial Indexing
class Article
  include Mongoid::Document
  include Mongoid::Timestamps

  field :title, :type => Stri...
Querying
near
Article.near(:location => [ -23.552314, -46.6500949 ])


db.articles.find( { location : { "$near" : [-23.552...
Querying
within center
Article.where(:location.within => { "$center" =>
[ [ -23.552314, -46.6500949 ], 10 ] })

db.article...
Querying
within box
box = [ [40, 40], [60, 60] ]
Article.where(:location.within => { "$box" => box })

box = [[40, 40], [6...
Alternativas?


 Geohash
 PostGis (PostgreSQL)
 SpatialLite (SQLite)
Just Build It: You don't need anyone's approval and in
fact, you probably won't get it, so don't even try

               ...
Geolocalização com MongoDB e Rails
Geolocalização com MongoDB e Rails
Upcoming SlideShare
Loading in …5
×

Geolocalização com MongoDB e Rails

3,441 views

Published on

Case de uso de MongoDB e Rails para geolocalização, apresentado na trilha NoSQL do TDC2010.

Published in: Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,441
On SlideShare
0
From Embeds
0
Number of Embeds
332
Actions
Shares
0
Downloads
35
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide






















  • Geolocalização com MongoDB e Rails

    1. 1. Geolocalização com mongoDB e Rails e outros nosql em startups Maurício Maia @mauricio
    2. 2. vitrines de produtos
    3. 3. cache de produtos
    4. 4. mongoDB > MySQL > Cassandra
    5. 5. Yahoo! Open Hack Day março 2010
    6. 6. PlaceHacker Sinatra, MongoDB, mongo-ruby-driver
    7. 7. Topical PlaceHacker rewrite Rails 3 MongoDB Mongoid Reconhecimento de Entidades
    8. 8. Topical Mapa de notícias
    9. 9. Topical Stream de notícias locais
    10. 10. Topical Mobile
    11. 11. Por que mongoDB? fácil flexível cases geospatial indexing
    12. 12. Cases analytics, real-time, documentos, geo-location
    13. 13. Show me the code!
    14. 14. Preparando $ gem install mongoid --pre $ gem install bson_ext Gemfile gem "mongoid", "2.0.0.beta.16" gem "bson_ext", "1.0.4" $ rails generate mongoid:config
    15. 15. Geospatial Indexing class Article   include Mongoid::Document   include Mongoid::Timestamps   field :title, :type => String   field :lead, :type => String   field :published_at, :type => Time   field :location, :type => Array   index [[ :location, Mongo::GEO2D ]], :min => 180, :max => 180   index :published_at, Mongo::DESCENDING end db.articles.ensureIndex( { location : "2d"}, { min : -180, max : 180 } )
    16. 16. Querying near Article.near(:location => [ -23.552314, -46.6500949 ]) db.articles.find( { location : { "$near" : [-23.552314, -46.6500949 ] } } )
    17. 17. Querying within center Article.where(:location.within => { "$center" => [ [ -23.552314, -46.6500949 ], 10 ] }) db.articles.find({location : {"$within" : {"$center" : [ [-23.552314, -46.6500949 ] , 10]}}})
    18. 18. Querying within box box = [ [40, 40], [60, 60] ] Article.where(:location.within => { "$box" => box }) box = [[40, 40], [60, 60]] db.articles.find({location : {"$within" : {"$box" : box}}}
    19. 19. Alternativas? Geohash PostGis (PostgreSQL) SpatialLite (SQLite)
    20. 20. Just Build It: You don't need anyone's approval and in fact, you probably won't get it, so don't even try Kevin Rose - Digg

    ×