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

When calculating geographic center, convert from degrees to radians before...

When calculating geographic center, convert from degrees to radians before computation, then back again before returning.
parent 0befaaf2
No related branches found
No related tags found
No related merge requests found
......@@ -220,6 +220,9 @@ module Geocoder
#
def self.geographic_center(points)
# convert lat, lon pairs to radians
points.map!{ |p| [to_radians(p[0]), to_radians(p[1])] }
# convert to Cartesian coordinates
x = []; y = []; z = []
points.each do |p|
......@@ -235,10 +238,11 @@ module Geocoder
# convert back to latitude/longitude
lon = Math.atan2(ya, xa)
hyp = Math.sqrt(xa * xa + ya * ya)
hyp = Math.sqrt(xa**2 + ya**2)
lat = Math.atan2(za, hyp)
[lat,lon]
# return answer in degrees
[to_degrees(lat), to_degrees(lon)]
end
##
......@@ -248,6 +252,13 @@ module Geocoder
degrees * (Math::PI / 180)
end
##
# Convert radians to degrees.
#
def self.to_degrees(radians)
(radians * 180.0) / Math::PI
end
##
# Query Google for geographic information about the given phrase.
#
......
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