[openstreetmap/openstreetmap-website] Allow more formats for internal latlon search (PR #5147)

Anton Khorev notifications at github.com
Sat Sep 7 00:20:24 UTC 2024


@AntonKhorev commented on this pull request.



> -
-    ew = captures.fetch("ew").casecmp?("w") ? -1 : 1
-    ewd = BigDecimal(captures.fetch("ewd", "0"))
-    ewm = BigDecimal(captures.fetch("ewm", "0"))
-    ews = BigDecimal(captures.fetch("ews", "0"))
-
-    lat = ns * (nsd + (nsm / 60) + (nss / 3600))
-    lon = ew * (ewd + (ewm / 60) + (ews / 3600))
-
-    { :lat => lat.round(6).to_s("F"), :lon => lon.round(6).to_s("F") }
+  def dms_to_decdeg(prefix, directions, captures)
+    extract_number = ->(suffix) { captures.fetch("#{prefix}#{suffix}", "0").sub(",", ".") }
+
+    positive_direction, negative_direction = directions.chars
+    sign = captures.fetch(prefix, positive_direction).casecmp?(negative_direction) ? "-" : ""
+    deg = if captures["#{prefix}m"] || captures["#{prefix}s"]

Because we don't need to do min/sec math with divisions and results that have to be rounded to some precision. This special case was previously here: https://github.com/openstreetmap/openstreetmap-website/blob/1fce0c00f12ac6bbb56ad7c05c8c9f53c0d6edb3/app/controllers/geocoder_controller.rb#L213-L214 except it was triggered not by a lack of min/sec but by the entire query being in a simplest format possible. So you had [1.1111111111 2.2222222222](https://www.openstreetmap.org/search?query=1.1111111111%202.2222222222) keeping lat/lon intact but [1.1111111111 N 2.2222222222 E](https://www.openstreetmap.org/search?query=1.1111111111%20N%202.2222222222%20E) going into math mode with rounding.

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

Message ID: <openstreetmap/openstreetmap-website/pull/5147/review/2287289283 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20240906/bddce60e/attachment.htm>


More information about the rails-dev mailing list