X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/3d906fe8c6303c00e399ce2dfecc3471959fbe6e..0b6f0c1d34f636c0cdde234f3a62a6ead2b8655f:/lib/osm.rb diff --git a/lib/osm.rb b/lib/osm.rb index 5be2da56a..789a5f439 100644 --- a/lib/osm.rb +++ b/lib/osm.rb @@ -334,6 +334,11 @@ module OSM maxlon = (@lon + lonradius) * 180 / PI return { :minlat => minlat, :maxlat => maxlat, :minlon => minlon, :maxlon => maxlon } end + + # get the SQL to use to calculate distance + def sql_for_distance(lat_field, lon_field) + "6372.795 * 2 * asin(sqrt(power(sin((radians(#{lat_field}) - #{@lat}) / 2), 2) + cos(#{@lat}) * cos(radians(#{lat_field})) * power(sin((radians(#{lon_field}) - #{@lon})/2), 2)))" + end end class GeoRSS