kristianmandrup / mongoid-geo Goto Github PK
View Code? Open in Web Editor NEWGeo-spatial extension for Mongoid 2
License: MIT License
Geo-spatial extension for Mongoid 2
License: MIT License
Not sure why this is the case. I think it is the way it is processed by rubygems.org you might want to look into using jewler to package your gem makes life a lot easier.
I apologize if this is user error or an obvious oversight on my part. I am trying various geoNear queries and am getting "undefined method 'distance=' for Model"
gem 'rails', '3.0.5'
gem 'mongoid', "~> 2.0.1"
gem 'mongoid_geo', "0.5.2"
class Place
include Mongoid::Document
extend Mongoid::Geo::Near
field :loc, type: Array, :geo => true
geo_index :loc
end
@places = Place.geoNear([lat, long], :loc)
And the resulting error:
NoMethodError (undefined method distance=' for #<Place:0x00000103a29b90>): app/controllers/places_controller.rb:19:in
index'
Hi,
I like this plugin now ! ;) And I just wonder if it would be possible to get the lat and lng in a way like this:
object.location.lat object.location.lng
Does it make sense ?
Thanks,
I'm currently using your gem in my project. After doing a bundle update, i got this error. My Gemfile
is configured to pull the master
branch of this code. I've got the issue with 19801bad24fa1649f431
commit:
Here's the full stack trace: https://gist.github.com/1016367
Thanks!
Hi,
I'm trying to use mongoid-geo with an existant project using omniauth.
But with mongoid-geo, I can't login any more.
Any idea ?
Thanks,
/Users/home/.bundler/ruby/1.9.1/mongoid-geo-b7e3f9fe78ae/lib/mongoid/geo/fields.rb:19:in `block (2 levels) in create_accessors' devise (1.2.rc) lib/devise/models/trackable.rb:16:in `update_tracked_fields!' mongoid (2.0.0.rc.7) lib/mongoid/relations/proxy.rb:124:in `method_missing' devise (1.2.rc) lib/devise/hooks/trackable.rb:7:in `block in ' warden (1.0.3) lib/warden/hooks.rb:14:in `call' warden (1.0.3) lib/warden/hooks.rb:14:in `block in _run_callbacks' warden (1.0.3) lib/warden/hooks.rb:9:in `each' warden (1.0.3) lib/warden/hooks.rb:9:in `_run_callbacks' warden (1.0.3) lib/warden/manager.rb:53:in `_run_callbacks' warden (1.0.3) lib/warden/proxy.rb:164:in `set_user' devise (1.2.rc) lib/devise/controllers/helpers.rb:112:in `sign_in' devise (1.2.rc) lib/devise/controllers/helpers.rb:204:in `sign_in_and_redirect' app/controllers/authentications_controller.rb:13:in `create' ...
are you create gems for this extension?
Hi when I do this :
Person.geo_near([45, -3], :pos)
I get this :
ruby-1.9.2-p180 :031 > Person.geoNear([45, -3, 10], :pos)
NoMethodError: undefined method from_point=' for #<Person:0x000000023a0938> from /home/dhruva/.rvm/gems/ruby-1.9.2-p180/gems/mongoid-2.0.2/lib/mongoid/attributes.rb:162:in
method_missing'
from /home/dhruva/.rvm/gems/ruby-1.9.2-p180/gems/mongoid_geo-0.6.1/lib/mongoid/geo/near.rb:71:in block in query_result' from /home/dhruva/.rvm/gems/ruby-1.9.2-p180/gems/mongoid_geo-0.6.1/lib/mongoid/geo/near.rb:67:in
map'
from /home/dhruva/.rvm/gems/ruby-1.9.2-p180/gems/mongoid_geo-0.6.1/lib/mongoid/geo/near.rb:67:in query_result' from /home/dhruva/.rvm/gems/ruby-1.9.2-p180/gems/mongoid_geo-0.6.1/lib/mongoid/geo/near.rb:34:in
geoNear'
from (irb):31
from /home/dhruva/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/commands/console.rb:44:in start' from /home/dhruva/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/commands/console.rb:8:in
start'
from /home/dhruva/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/commands.rb:23:in <top (required)>' from script/rails:6:in
require'
from script/rails:6:in `
Invalid gemspec in [/Library/Ruby/Gems/1.8/specifications/mongoid_geo-0.5.3.gemspec]: invalid date format in specification: "2011-05-09 00:00:00.000000000Z"
I'm using ruby 1.8.7 and rubygems 1.7.2 on mac OS X.
i have include mongoid_geo in my gemfile
and this is my model
class Location
include Mongoid::Document
include Mongoid::Timestamps
field :name, :type => String
field :description, :type => String
field :latlng, :type => Array, :geo => true
geo_index :latlng
end
but when i create a location it shows error like this:
Field was defined as a(n) Array, but received a String with the value "-6.905033, 107.611539"
{"utf8"=>"✓",
"authenticity_token"=>"SKXnsMo613fky4DMn2F9R0TiOul/21hSg+sk7GC7b4Q=",
"location"=>{"name"=>"Saint Coffee",
"description"=>"tempat ngopi",
"address"=>"",
"latlng"=>"-6.905033,
107.611539",
"accuracy"=>"0",
"total_rating"=>"0",
"total_comment"=>"0",
"total_menu_rating"=>"0",
"total_menu_comment"=>"0"},
"commit"=>"Create Location"}
am i missing something when i install mongoid_geo gem
ref: db7ae0a
Why was geoNear removed? This is an actual MongoDB command. Removal of it seems strange.
Quick bug-report:
When using the geo_near
method, it fails, if the klass
has a namespace-name, e.g. Foo::Bar::Model
. The result is that the collection-name sent to mongo will look like this: foo/bar/model
instead of foo_bar_model
.
I've monkey patched this in my project, but perhaps you can fix it in the gem as well.
When doing to_criteria on a result set, what's the best way to keep the distance intact and keep the sort order based on distance?
Invalid gemspec in [/Users/username/.rvm/gems/ruby-1.8.7-p299/specifications/mongoid_geo-0.4.1.gemspec]: invalid date format in specification: "2011-04-08 00:00:00.000000000Z"
Getting this after a recent update.
(in mongoid-geo)
/usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/rake.rb:30: warning: already initialized constant RAKEVERSION
WARNING: Possible conflict with Rake extension: String#ext already exists
WARNING: Possible conflict with Rake extension: String#pathmap already exists
/usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/rake.rb:402: warning: already initialized constant EMPTY_TASK_ARGS
/usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/rake.rb:450: warning: already initialized constant EMPTY
/usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/rake.rb:958: warning: already initialized constant RUBY_EXT
/usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/rake.rb:962: warning: already initialized constant RUBY
/usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/rake.rb:1031: warning: already initialized constant LN_SUPPORTED
/usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/rake.rb:1240: warning: already initialized constant ARRAY_METHODS
/usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/rake.rb:1243: warning: already initialized constant MUST_DEFINE
/usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/rake.rb:1247: warning: already initialized constant MUST_NOT_DEFINE
/usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/rake.rb:1251: warning: already initialized constant SPECIAL_RETURN
/usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/rake.rb:1257: warning: already initialized constant DELEGATING_METHODS
/usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/rake.rb:1561: warning: already initialized constant DEFAULT_IGNORE_PATTERNS
/usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/rake.rb:1567: warning: already initialized constant DEFAULT_IGNORE_PROCS
/usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/rake.rb:1604: warning: already initialized constant FileList
/usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/rake.rb:1630: warning: already initialized constant EARLY
/usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/rake.rb:1960: warning: already initialized constant DEFAULT_RAKEFILES
rake aborted!
stack level too deep
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:2383
if I have a form field with values populated from the database of existing latlng values...
So that in model:
Field :latlng, :type => Float, :geo => true
then
in view i have a form field:
map[latlng] with values: "[some lat number float, some lng number float]"
on save, the database persists:
[0, some lng number float]
Hi,
Are there any plans to add support for Mongoid Geonear queries ? It has the added information about distance to the location. I need this information in my app.
regards
Jeroen
mongoid-geo assume the location data is stored as [lat,lng], but if I want to use Spherical Model of monodb,it must stored as [lng,lat]. does mongoid-goe has any plan or suggestion for this?
I played with the gem ~2 weeks ago and came across this:
/home/gabe/.rvm/gems/ree-1.8.7-2011.03@shady/gems/mongoid_geo-0.6.0/lib/mongoid/geo/index.rb:9:in `geo_index':
undefined method `define_singleton_method' for Spot:Class (NoMethodError)
So I bundled from git, and was able to at least start my server, but then wasn't able to do anything useful. Mostly I saw a lot of this:
RuntimeError (Invalid Geo Input. Please use either a Hash or an Array. Remember that Longitude must always be the first value in an Array.):
I took another look at my project today, and screwed with a bunch of different stuff trying to get it to work, read GH-40, so I went back to the gem, but got the same undefined method error as above.
Finally I tried the gem in Ruby 1.9.2 p180, and it worked as advertised.
I understand you're working on a release that may shortly fix this issue. But I still wanted to post this hoping to save other folks' time who are running REE.
A few small (breaking) issues in the current gemfile:
I started to test in my fork, but ran into the sugar-high dependency issue... Kristian, I haven't looked closely to see how calc and vectors are being used and am heading out the door for meetings now. Here's the minor gemfile edit I was trying to test:
source :rubygems
gem 'mongoid', '>=2'
gem "bson_ext", '>=1.3', :platforms => :mri
gem 'activesupport', '>=3'
gem 'geo_calc', '~> 0.6.1'
gem 'geo_vectors', '~> 0.5.1'
group :test, :development do
gem 'rspec', '>=2.4'
gem 'bundler', '>=1'
gem 'jeweler', '>=1.5'
gem 'rdoc', '>=3.6'
end
group :test do
gem 'rails', '>=3.0'
gem 'rspec-rails', '>=2.6'
gem 'capybara', '>=0.4'
end
With the recent changes to how indexes are defined and are created some problems have crept up. Here is the stack error.
/home/salbito/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/mongoid-geo-24f205367686/lib/mongoid/geo/index.rb:9:in `geo_index': undefined method `define_singleton_method' for Ping:Class (NoMethodError)
from /home/salbito/Source/PingPang/app/models/ping.rb:9
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:239:in `require'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:239:in `require'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:227:in `load_dependency'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:239:in `require'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:346:in `require_or_load'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:300:in `depend_on'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:216:in `require_dependency'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/mongoid-8f827db43826/lib/rails/mongoid.rb:55:in `load_model'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/mongoid-8f827db43826/lib/rails/mongoid.rb:18:in `load_models'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/mongoid-8f827db43826/lib/rails/mongoid.rb:17:in `each'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/mongoid-8f827db43826/lib/rails/mongoid.rb:17:in `load_models'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/gems/railties-3.0.7/lib/rails/paths.rb:102:in `each'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/gems/railties-3.0.7/lib/rails/paths.rb:102:in `each'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/mongoid-8f827db43826/lib/rails/mongoid.rb:16:in `load_models'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/mongoid-8f827db43826/lib/mongoid/railtie.rb:86:in `_callback_before_5'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-3.0.7/lib/active_support/callbacks.rb:425:in `_run_prepare_callbacks'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/gems/actionpack-3.0.7/lib/action_dispatch/middleware/callbacks.rb:40:in `initialize'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/gems/actionpack-3.0.7/lib/action_dispatch/middleware/stack.rb:33:in `new'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/gems/actionpack-3.0.7/lib/action_dispatch/middleware/stack.rb:33:in `build'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/gems/actionpack-3.0.7/lib/action_dispatch/middleware/stack.rb:79:in `build'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/gems/railties-3.0.7/lib/rails/application.rb:209:in `inject'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/gems/actionpack-3.0.7/lib/action_dispatch/middleware/stack.rb:79:in `each'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/gems/actionpack-3.0.7/lib/action_dispatch/middleware/stack.rb:79:in `inject'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/gems/actionpack-3.0.7/lib/action_dispatch/middleware/stack.rb:79:in `build'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/gems/railties-3.0.7/lib/rails/application.rb:162:in `build_middleware_stack'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/gems/railties-3.0.7/lib/rails/application/finisher.rb:35
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/gems/railties-3.0.7/lib/rails/initializable.rb:25:in `instance_exec'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/gems/railties-3.0.7/lib/rails/initializable.rb:25:in `run'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/gems/railties-3.0.7/lib/rails/initializable.rb:50:in `run_initializers'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/gems/railties-3.0.7/lib/rails/initializable.rb:49:in `each'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/gems/railties-3.0.7/lib/rails/initializable.rb:49:in `run_initializers'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/gems/railties-3.0.7/lib/rails/application.rb:134:in `initialize!'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/gems/railties-3.0.7/lib/rails/application.rb:77:in `send'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/gems/railties-3.0.7/lib/rails/application.rb:77:in `method_missing'
from /home/salbito/Source/PingPang/config/environment.rb:5
from /home/salbito/Source/PingPang/spec/spec_helper.rb:3:in `require'
from /home/salbito/Source/PingPang/spec/spec_helper.rb:3
from /home/salbito/Source/PingPang/spec/models/choice_spec.rb:1:in `require'
from /home/salbito/Source/PingPang/spec/models/choice_spec.rb:1
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/gems/rspec-core-2.6.2/lib/rspec/core/configuration.rb:419:in `load'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/gems/rspec-core-2.6.2/lib/rspec/core/configuration.rb:419:in `load_spec_files'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/gems/rspec-core-2.6.2/lib/rspec/core/configuration.rb:419:in `map'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/gems/rspec-core-2.6.2/lib/rspec/core/configuration.rb:419:in `load_spec_files'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/gems/rspec-core-2.6.2/lib/rspec/core/command_line.rb:18:in `run'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/gems/rspec-core-2.6.2/lib/rspec/core/runner.rb:80:in `run_in_process'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/gems/rspec-core-2.6.2/lib/rspec/core/runner.rb:69:in `run'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/gems/rspec-core-2.6.2/lib/rspec/core/runner.rb:11:in `autorun'
from /home/salbito/.rvm/gems/ree-1.8.7-2010.02/bin/rspec:19
ref: db7ae0a
Why was geoNear removed? This is an actual MongoDB command. Removal of it seems strange.
Gemspec should not have a bson_ext dependency - breaks under jruby
On persisted objects this bug occurs when the mongoid_geo 0.6.0 is loaded. I originally thought it was a mongoid bug so the discussion is here:
Hi,
I get nil
as the return value for the following method call:
Place.geoNear(another_place.location, :location).first.to_model.distance
Every item in the result set returns nil
for distance.
I'm using Mongoid 2.0.1 and Mongo 1.8.0.
I set Mongoid::Geo.mongo_db_version = 1.8
in an initializer.
The search query in to_model (geo_near.rb) returns a nil value.
Changing this:
klass.where(:_id => _id).first.extend(Mongoid::Geo::Distance)
to:
klass.criteria.id(_id).first.extend(Mongoid::Geo::Distance)
might solve it…?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.