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

Improve SQLite distance calculation.

Multiply by .707 (sin(45)) instead of .5.
parent f4738836
Branches
Tags
No related merge requests found
...@@ -157,8 +157,11 @@ module Geocoder::Orm ...@@ -157,8 +157,11 @@ module Geocoder::Orm
dx = Geocoder::Calculations.longitude_degree_distance(30, options[:units] || :mi) dx = Geocoder::Calculations.longitude_degree_distance(30, options[:units] || :mi)
dy = Geocoder::Calculations.latitude_degree_distance(options[:units] || :mi) dy = Geocoder::Calculations.latitude_degree_distance(options[:units] || :mi)
distance = "(#{dy} * ABS(#{lat_attr} - #{latitude}) / 2) + " + # sin of 45 degrees = average x or y component of vector
"(#{dx} * ABS(#{lon_attr} - #{longitude}) / 2)" factor = Math.sin(Math::PI / 4)
distance = "(#{dy} * ABS(#{lat_attr} - #{latitude}) * #{factor}) + " +
"(#{dx} * ABS(#{lon_attr} - #{longitude}) * #{factor})"
default_near_scope_options(latitude, longitude, radius, options).merge( default_near_scope_options(latitude, longitude, radius, options).merge(
:select => "#{options[:select] || '*'}, " + :select => "#{options[:select] || '*'}, " +
"#{distance} AS distance" + "#{distance} AS distance" +
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment