This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
{SOLVED} Convert Lat/Long Dec to Deg & minutes
#1
Does anyone know how to convert Latitude and Longitude from "Degrees,Decimal Degrees" as output by SignalK to "Degrees,Minute,Dec Minutes" ?
Node Code would be great if you have it  Big Grin

Thanks
Reply
#2
(2018-03-10, 03:31 PM)affinite Wrote: Does anyone know how to convert Latitude and Longitude from "Degrees,Decimal Degrees" as output by SignalK to "Degrees,Minute,Dec Minutes" ?
Node Code would be great if you have it  Big Grin

Thanks

Don't get me wrong but what did you do to achieve your goal and how did you fail?

Since your last node-red question you know that you can use javascript in node-red. You are aware of the function node and if you would have looked at my code example you might have understood how to get data in the node and how to return the data.
There are many javascript snippets on the world wide web. Solving this is just a matter of 1min google.
Reply
#3
Thanks for your help
Reply
#4
(2018-03-10, 03:31 PM)affinite Wrote: Does anyone know how to convert Latitude and Longitude from "Degrees,Decimal Degrees" as output by SignalK to "Degrees,Minute,Dec Minutes" ?
Node Code would be great if you have it  Big Grin

Thanks

OK so after several hours with google I have put together two (crude) nodes. One for Latitude and one for Longitude
They convert Degrees/Decimal Degrees (as per signalK key) to Degrees/Minutes/Decimal Minutes (to 3 decimal places)
Tests for N/S E/W and inserts "N/S" or "E/W" as appropriate  
If you see any mistakes or errors please let me know

Code

[{"id":"7448e190.e1747","type":"function","z":"115f1f92.45423","name":"navigation.position.latitude","func":"var signalk_key=\"navigation.position\";\n\nif(msg.payload.hasOwnProperty(signalk_key)){\n    msg.payload=msg.payload[signalk_key][\"latitude\"];\n    return msg;\n}","outputs":1,"noerr":0,"x":660,"y":360,"wires":[["6c49fa30.7cdf74"]]},{"id":"3e5cb9e9.62a0c6","type":"ui_text","z":"115f1f92.45423","group":"251f77ed.6b1808","order":1,"width":"4","height":"1","name":"Latitude","label":"<font size=\"5\">Lat","format":"<font size=\"6\">{{msg.payload}}","layout":"row-spread","x":1140,"y":360,"wires":[]},{"id":"6c49fa30.7cdf74","type":"function","z":"115f1f92.45423","name":"Convert Latitude Format","func":"var degDecimaldeg = msg.payload;\nif (degDecimaldeg >0) NS=\"N\" ; else NS=\"S\"\nvar degrees = parseInt(degDecimaldeg);\nvar decimalDeg = degDecimaldeg - degrees;\nvar minutes = decimalDeg*60\nvar minutes3dp = minutes.toFixed(3)\nvar deg = degrees.toString()\nvar deg = deg.replace(\"-\", \"\")\nvar min = minutes3dp.toString()\nvar min = min.replace(\"-\", \"\")\nmsg.payload = deg + \"\\u00B0\" + \"   \" + min + \"' \" + NS\nreturn msg;","outputs":1,"noerr":0,"x":930,"y":360,"wires":[["3e5cb9e9.62a0c6"]]},{"id":"c027394d.fb7458","type":"ui_text","z":"115f1f92.45423","group":"251f77ed.6b1808","order":2,"width":"4","height":"1","name":"Longitude","label":"<font size=\"5\">Long","format":"<font size=\"6\">{{msg.payload}}","layout":"row-spread","x":1140,"y":400,"wires":[]},{"id":"d1da8bed.1bc3c8","type":"function","z":"115f1f92.45423","name":"Convert Longitude Format","func":"var degDecimaldeg = msg.payload;\nif (degDecimaldeg >0) WE=\"E\" ; else WE=\"W\"\nvar degrees = parseInt(degDecimaldeg);\nvar decimalDeg = degDecimaldeg - degrees;\nvar minutes = decimalDeg*60\nvar minutes3dp = minutes.toFixed(3)\nvar deg = degrees.toString()\nvar deg = deg.replace(\"-\", \"\")\nvar min = minutes3dp.toString()\nvar min = min.replace(\"-\", \"\")\nmsg.payload = deg + \"\\u00B0\"+ \"   \" + min + \"' \" + WE\nreturn msg;","outputs":1,"noerr":0,"x":930,"y":400,"wires":[["c027394d.fb7458"]]},{"id":"49f0691d.a338d8","type":"function","z":"115f1f92.45423","name":"navigation.position.longitude","func":"var signalk_key=\"navigation.position\";\n\nif(msg.payload.hasOwnProperty(signalk_key)){\n    msg.payload=msg.payload[signalk_key][\"longitude\"];\n    return msg;\n}","outputs":1,"noerr":0,"x":660,"y":400,"wires":[["d1da8bed.1bc3c8"]]},{"id":"251f77ed.6b1808","type":"ui_group","z":"","name":"Position/Environment","tab":"68583212.87cb0c","order":3,"disp":true,"width":"4"},{"id":"68583212.87cb0c","type":"ui_tab","z":"","name":"Navigation","icon":"dashboard","order":3}]
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)