Skip to content
Snippets Groups Projects
Commit ee670d37 authored by Alex Reisner's avatar Alex Reisner
Browse files

Merge branch 'master' of github.com:alexreisner/geocoder

parents 8408f3ad 604a6f86
No related branches found
No related tags found
No related merge requests found
source "http://rubygems.org" source "http://rubygems.org"
gemspec
group :development, :test do group :development, :test do
gem 'rake' gem 'rake'
gem 'mongoid' gem 'mongoid', '3.0.13'
gem 'bson_ext', :platforms => :ruby gem 'bson_ext', :platforms => :ruby
gem 'rails' gem 'rails'
...@@ -13,3 +11,5 @@ group :development, :test do ...@@ -13,3 +11,5 @@ group :development, :test do
gem 'jruby-openssl' gem 'jruby-openssl'
end end
end end
gemspec
...@@ -590,6 +590,26 @@ You can also do this to raise all exceptions: ...@@ -590,6 +590,26 @@ You can also do this to raise all exceptions:
See `lib/geocoder/exceptions.rb` for a list of raise-able exceptions. See `lib/geocoder/exceptions.rb` for a list of raise-able exceptions.
Troubleshooting
---------------
### Mongoid
If you get one of these errors:
uninitialized constant Geocoder::Model::Mongoid
uninitialized constant Geocoder::Model::Mongoid::Mongo
you should check your Gemfile to make sure the Mongoid gem is listed _before_ Geocoder. If Mongoid isn't loaded when Geocoder is initialized, Geocoder will not load support for Mongoid.
### ActiveRecord
A lot of debugging time can be saved by understanding how Geocoder works with ActiveRecord. When you use the `near` scope or the `nearbys` method of a geocoded object, Geocoder creates an ActiveModel::Relation object which adds some attributes (eg: distance, bearing) to the SELECT clause. It also adds a condition to the WHERE clause to check that distance is within the given radius. Because the SELECT clause is modified, anything else that modifies the SELECT clause may produce strange results, for example:
* using the `pluck` method (selects only a single column)
* specifying another model through `includes` (selects columns from other tables)
Known Issue Known Issue
----------- -----------
......
...@@ -11,7 +11,8 @@ module Geocoder ...@@ -11,7 +11,8 @@ module Geocoder
# http://www.scribd.com/doc/2569355/Geo-Distance-Search-with-MySQL # http://www.scribd.com/doc/2569355/Geo-Distance-Search-with-MySQL
# #
def full_distance(latitude, longitude, lat_attr, lon_attr, options = {}) def full_distance(latitude, longitude, lat_attr, lon_attr, options = {})
earth = Geocoder::Calculations.earth_radius(options[:units] || :mi) units = options[:units] || Geocoder::Configuration.units
earth = Geocoder::Calculations.earth_radius(units)
"#{earth} * 2 * ASIN(SQRT(" + "#{earth} * 2 * ASIN(SQRT(" +
"POWER(SIN((#{latitude.to_f} - #{lat_attr}) * PI() / 180 / 2), 2) + " + "POWER(SIN((#{latitude.to_f} - #{lat_attr}) * PI() / 180 / 2), 2) + " +
...@@ -31,8 +32,9 @@ module Geocoder ...@@ -31,8 +32,9 @@ module Geocoder
# are not intended for use in production! # are not intended for use in production!
# #
def approx_distance(latitude, longitude, lat_attr, lon_attr, options = {}) def approx_distance(latitude, longitude, lat_attr, lon_attr, options = {})
dx = Geocoder::Calculations.longitude_degree_distance(30, options[:units] || :mi) units = options[:units] || Geocoder::Configuration.units
dy = Geocoder::Calculations.latitude_degree_distance(options[:units] || :mi) dx = Geocoder::Calculations.longitude_degree_distance(30, units)
dy = Geocoder::Calculations.latitude_degree_distance(units)
# sin of 45 degrees = average x or y component of vector # sin of 45 degrees = average x or y component of vector
factor = Math.sin(Math::PI / 4) factor = Math.sin(Math::PI / 4)
...@@ -61,7 +63,7 @@ module Geocoder ...@@ -61,7 +63,7 @@ module Geocoder
# http://www.beginningspatial.com/calculating_bearing_one_point_another # http://www.beginningspatial.com/calculating_bearing_one_point_another
# #
def full_bearing(latitude, longitude, lat_attr, lon_attr, options = {}) def full_bearing(latitude, longitude, lat_attr, lon_attr, options = {})
case options[:bearing] case options[:bearing] || Geocoder::Configuration.distances
when :linear when :linear
"CAST(" + "CAST(" +
"DEGREES(ATAN2( " + "DEGREES(ATAN2( " +
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment