{"id":2191,"date":"2025-01-26T23:26:41","date_gmt":"2025-01-27T04:26:41","guid":{"rendered":"https:\/\/www.unliterate.net\/?p=2191"},"modified":"2025-01-26T23:31:59","modified_gmt":"2025-01-27T04:31:59","slug":"gps","status":"publish","type":"post","link":"https:\/\/www.unliterate.net\/index.php\/2025\/01\/26\/gps\/","title":{"rendered":"GPS"},"content":{"rendered":"\n<p>I&#8217;ve always wanted to learn how to convert GPS coordinates without &#8220;knowing&#8221;, like it should be common sense. I came across a pair of coordinates, both the DMS and the DD formats and decided to start breaking things down.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>DMS, or Degrees\/Minutes\/Seconds is a way to express GPS as divisions of 60 minutes and 60 seconds. The earth is 12,756km at the equator, so every degree would be 35.43km, every minute would be 590m, and every second should be 9m. An example would be 28\u00b032\u203258\u2033N 84\u00b033\u203243\u2033E<\/p>\n\n\n\n<p>DD is Decimal Degrees and is an easier way to express GPS fine-tuned portions of the Degree by using fractional digits. An example would be 28.54944\u00b0N 84.56194\u00b0E<\/p>\n\n\n\n<p>Converting from DMS to DD appeared to be quite easy:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>32 \/ 60   = 0.5333333333333333\n58 \/ 3660 = 0.0161111111111111\n   +      = 0.54944\n\n33 \/ 60   = 0.55\n43 \/ 3600 = 0.0119444444444444\n   +      = 0.56194<\/code><\/pre>\n\n\n\n<p>Converting from DD also presented little challenge:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>0.54944 * 60 = 32.9664 -&gt; FLOOR() -&gt; 32\n32.9664 - 32 = 0.9664\n0.9664 * 60  = 57.984 -&gt; ROUND() -&gt; 58\n\n0.56194 * 60 = 33.7164 -&gt; FLOOR() -&gt; 33\n33.7164 - 33 = 0.7164\n0.7164 * 60  = 42.984 -&gt; ROUND() -&gt; 43<\/code><\/pre>\n\n\n\n<p>A small javascript converter would look like this:<\/p>\n\n\n\nDMS &lt;-&gt; DD<br \/>\nDMS\/Degree: <input type=\"text\" id=\"degree\" onkeyup=\"calculate('dms');\" value=\"0\" \/><br \/>\nDMS\/Minute: <input type=\"text\" id=\"minute\" onkeyup=\"calculate('dms');\" value=\"0\" \/><br \/>\nDMS\/Second: <input type=\"text\" id=\"second\" onkeyup=\"calculate('dms');\" value=\"0\" \/><br \/>\nDD\/Decimal: <input type=\"text\" id=\"decimal\" onkeyup=\"calculate('dd');\" value=\"0\" \/>\n<script>\nfunction calculate(type) {\n  gps = new Object();\n  items = ['degree', 'minute', 'second', 'decimal'];\n  \/* Load the stuff up *\/\n  for (let i = 0; i < items.length; i++) {\n    gps[items[i]] = document.getElementById(items[i]);\n    gps[items[i] + 'Value'] = parseFloat(document.getElementById(items[i]).value);\n  }\n  if (type == \"dms\") {\n    \/* Easiest to do *\/\n    console.log(\"Calculating DMS to DD\");\n    let result = gps['degreeValue'] + (gps['minuteValue'] \/ 60) + (gps['secondValue'] \/ 3600);\n    gps['decimal'].value = result.toFixed(6);\n  }\n  if (type == \"dd\") {\n    \/* A bit complicated, but math nontheless *\/\n    console.log(\"Calculating DD to DMS\");\n    gps['degree'].value = Math.floor(gps['decimalValue']);\n    let remainder = gps['decimalValue'] - Math.floor(gps['decimalValue'])\n    gps['minute'].value = Math.floor(remainder * 60);\n    remainder = (remainder * 60) - Math.floor(remainder * 60);\n    gps['secondValue'] = remainder * 60;\n    gps['second'].value = gps['secondValue'].toFixed(6);\n  }\n}\n<\/script>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve always wanted to learn how to convert GPS coordinates without &#8220;knowing&#8221;, like it should be common sense. I came across a pair of coordinates, both the DMS and the DD formats and decided to start breaking things down.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-2191","post","type-post","status-publish","format-standard","hentry","category-random"],"_links":{"self":[{"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/posts\/2191","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/comments?post=2191"}],"version-history":[{"count":3,"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/posts\/2191\/revisions"}],"predecessor-version":[{"id":2195,"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/posts\/2191\/revisions\/2195"}],"wp:attachment":[{"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/media?parent=2191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/categories?post=2191"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/tags?post=2191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}