diff --git a/lib/geocoder/calculations.rb b/lib/geocoder/calculations.rb index 84f4e339b4413991a3d35c6bdb29dc77db92b0c4..f2531922e41ef0c19a0d6b6681f1d5704681411f 100644 --- a/lib/geocoder/calculations.rb +++ b/lib/geocoder/calculations.rb @@ -120,7 +120,7 @@ module Geocoder def geographic_center(points) # convert objects to [lat,lon] arrays and remove nils - points.map!{ |p| p.is_a?(Array) ? p : p.to_coordinates }.compact + points = points.map{ |p| p.is_a?(Array) ? p : p.to_coordinates }.compact # convert degrees to radians points.map!{ |p| to_radians(p) } diff --git a/test/geocoder_test.rb b/test/geocoder_test.rb index bb1874c3d071c9c826a13081959bc4779b07d024..cad207d299250d52250ffe1183fe320abce60fb0 100644 --- a/test/geocoder_test.rb +++ b/test/geocoder_test.rb @@ -51,6 +51,14 @@ class GeocoderTest < Test::Unit::TestCase assert Geocoder.address(40.750354, -73.993371).is_a?(String) end + def test_geographic_center_doesnt_overwrite_argument_value + # this tests for the presence of a bug that was introduced in version 0.9.11 + orig_points = [[52,8], [46,9], [42,5]] + points = orig_points.clone + Geocoder::Calculations.geographic_center(points) + assert_equal orig_points, points + end + # --- general ---