我有一个循环
suburb_gps = [-35.44454, 127.4323423]
tradies_in_area.delete_if do |tradie|
gps_coor = suburb_gps
tradie.tradie_locations.first.radius < (Geography.distance(tradie.tradie_locations.first.get_lat_and_lon, gps_coor) / 1000)
end
在循环中,您注意到我将变量分配gps_coor
给suburb_gps
. 然后我使用确定两个坐标之间距离gps_coor
的方法。distance
我的主要问题是在第一个循环之后suburb_gps
变量会发生变化,并且在每个循环之后都会不断变化。我不知道为什么它搞砸了。这get_lat_and_lon
是我的模型类的实例方法
def get_lat_and_lon
[self.latitude, self.longitude]
end
我不知道为什么suburb_gps
每次循环后变量都会改变。任何帮助将非常感激。谢谢。
以下是在循环之后的郊区_gps 等于的一些东西
2013-11-06T21:12:10.789459+00:00 app[web.1]: [-7.297875028610691e-286, 4.08087004920688e-285]
2013-11-06T21:12:10.789459+00:00 app[web.1]: [-1.2737194764833194e-287, 7.122461870468308e-287]
2013-11-06T21:12:10.789459+00:00 app[web.1]: [-2.223059861141241e-289, 1.2431041048742584e-288]
2013-11-06T21:12:10.789749+00:00 app[web.1]: [-3.87997140458426e-291, 2.16962595751127e-290]
2013-11-06T21:12:10.789897+00:00 app[web.1]: [-1.181906878110669e-294, 6.609058610793502e-294]
2013-11-06T21:12:10.789749+00:00 app[web.1]: [-6.771827589322435e-293, 3.786711649530626e-292]
2013-11-06T21:12:10.789897+00:00 app[web.1]: [-2.062816647499847e-296, 1.1534983321562906e-295]
2013-11-06T21:12:10.790298+00:00 app[web.1]: [-6.283698846544718e-300, 3.51375685669721e-299]
2013-11-06T21:12:10.790298+00:00 app[web.1]: [-1.0967123407597525e-301, 6.132662626389288e-301]
2013-11-06T21:12:10.790298+00:00 app[web.1]: [-3.6002942363823585e-298, 2.0132343812390454e-297]
2013-11-06T21:12:10.790298+00:00 app[web.1]: [-1.914124129351169e-303, 1.0703515474449596e-302]
2013-11-06T21:12:10.790298+00:00 app[web.1]: [-3.340776834904773e-305, 1.8681158656730845e-304]
2013-11-06T21:12:10.790579+00:00 app[web.1]: [-5.8307555343443306e-307, 3.260477266473944e-306]
2013-11-06T21:12:10.790579+00:00 app[web.1]: [-1.017658819531899e-308, 5.690606348639485e-308]
2013-11-06T21:12:10.790579+00:00 app[web.1]: [-1.77614970627906e-310, 9.93198172186515e-310]
2013-11-06T21:12:10.790579+00:00 app[web.1]: [-3.09996603829e-312, 1.733457822944e-311]
2013-11-06T21:12:10.790942+00:00 app[web.1]: [-1.648121e-317, 9.216062e-317]
2013-11-06T21:12:10.790579+00:00 app[web.1]: [-5.410461407e-314, 3.02545464546e-313]
2013-11-06T21:12:10.790942+00:00 app[web.1]: [-9.44303657e-316, 5.280414494e-315]
2013-11-06T21:12:10.790942+00:00 app[web.1]: [-5.02e-321, 2.8073e-320]
2013-11-06T21:12:10.790942+00:00 app[web.1]: [-0.0, 1.0e-323]
2013-11-06T21:12:10.790942+00:00 app[web.1]: [-2.8765e-319, 1.608505e-318]
2013-11-06T21:12:10.790942+00:00 app[web.1]: [-9.0e-323, 4.9e-322]
2013-11-06T21:12:10.790942+00:00 app[web.1]: [-0.0, 0.0]
2013-11-06T21:12:10.791683+00:00 app[web.1]: [-0.0, 0.0]
2013-11-06T21:12:10.791683+00:00 app[web.1]: [-0.0, 0.0]
2013-11-06T21:12:10.791683+00:00 app[web.1]: [-0.0, 0.0]
2013-11-06T21:12:10.791683+00:00 app[web.1]: [-0.0, 0.0]
2013-11-06T21:12:10.792060+00:00 app[web.1]: [-0.0, 0.0]
输出继续打印[-0.0, 0.0]
,直到循环完成。