[openstreetmap/openstreetmap-website] Avoid use of scientific notation in geocoder results (PR #4961)

Anton Khorev notifications at github.com
Thu Jul 11 14:15:26 UTC 2024


@AntonKhorev requested changes on this pull request.



>  
-  def dms_to_decdeg(captures)
-    begin
-      Float(captures[0])
-      lat = captures[4].casecmp("s").zero? ? -(captures[0].to_f + ((captures[1].to_f + (captures[2].to_f / 60)) / 60)) : captures[0].to_f + ((captures[1].to_f + (captures[2].to_f / 60)) / 60)
-      lon = captures[9].casecmp("w").zero? ? -(captures[5].to_f + ((captures[6].to_f + (captures[7].to_f / 60)) / 60)) : captures[5].to_f + ((captures[6].to_f + (captures[7].to_f / 60)) / 60)
-    rescue StandardError
-      lat = captures[0].casecmp("s").zero? ? -(captures[1].to_f + ((captures[2].to_f + (captures[3].to_f / 60)) / 60)) : captures[1].to_f + ((captures[2].to_f + (captures[3].to_f / 60)) / 60)
-      lon = captures[5].casecmp("w").zero? ? -(captures[6].to_f + ((captures[7].to_f + (captures[8].to_f / 60)) / 60)) : captures[6].to_f + ((captures[7].to_f + (captures[8].to_f / 60)) / 60)
-    end
-    { :lat => lat, :lon => lon }
+    lat = ns * (nsd + (nsm / 60) + (nss / 3600))
+    lon = ew * (ewd + (ewm / 60) + (ews / 3600))
+
+    { :lat => lat.to_s("F"), :lon => lon.to_s("F") }

Need to `.truncate()` to some reasonable precision before `.to_s` or else the length blows up:

![image](https://github.com/openstreetmap/openstreetmap-website/assets/4158490/38852968-1c8f-4d02-bda7-0fd871a02eef)


-- 
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/4961#pullrequestreview-2172031821
You are receiving this because you are subscribed to this thread.

Message ID: <openstreetmap/openstreetmap-website/pull/4961/review/2172031821 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20240711/c024c38e/attachment-0001.htm>


More information about the rails-dev mailing list