Function node accuracy to setup worldmap

#1

Hi,

Can someone explain me how to write a function node to correctltly setup an acceptable accuracy in Worlmap... to be able to see the orange icon on the map?

Issues :

  • no refresh and no autozoom/autocenter on the map, each time the device is sending a new position (simulated with timestamps).

Below, the nodes

[{"id":"a2c38421.d88cc8","type":"tab","label":"MLS","disabled":false,"info":""},{"id":"92723490.c5de38","type":"switch","z":"a2c38421.d88cc8","name":"SORT INCOMING","property":"payload","propertyType":"msg","rules":[{"t":"regex","v":"^IWAP01","vt":"str","case":false}],"checkall":"true","repair":false,"outputs":1,"x":294.00001525878906,"y":132.80000114440918,"wires":[["5394b085.7cd4e"]]},{"id":"b880d0a5.2648e","type":"comment","z":"a2c38421.d88cc8","name":"INCOMING MESSAGES","info":"","x":145.3000030517578,"y":44,"wires":[]},{"id":"f6958e04.e1609","type":"inject","z":"a2c38421.d88cc8","name":"Valid IWAP01","topic":"","payload":"IWAP01190215A2232.9806N11404.9355E000.1061830323.8706000908000102,226,10,1440,22327#","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":94.5,"y":90.00000381469727,"wires":[["92723490.c5de38"]]},{"id":"5394b085.7cd4e","type":"function","z":"a2c38421.d88cc8","name":"AP01 split flag A/else","func":"// flag = A\n//IWAP01080524A2232.9806N11404.9355E000.1061830323.8706000908000102,460,0,9520,3671#\n// flag = V\n//IWAP01080524V0000.0000N00000.0000E000.1061830323.8706000908000102,460,0,9520,3671,Home|74-DE-2B-44-88-8C|97&Home1|74-DE-2B-44-88-8C|97&Home2|74-DE-2B-44-88-8C|97&Home3|74-DE-2B-44-88-8C|97# \nlet answer = {}\nlet elements = msg.payload.replace('#','').split(\",\")                                                           // this gives an array containing the bits\n// elements[0] is the long string starting IWAP01\nanswer.command = elements[0].substr(0,6)\nlet dateStr = elements[0].substr(6,6)                                                                           // eg \"190215\" 15th Feb 2019\nanswer.date = new Date(Number(dateStr.substr(0,2))+2000, Number(dateStr.substr(2,2))-1, dateStr.substr(4,2))    // 080524 - date\nanswer.flag = (elements[0].substr(12,1))                                                                        // true or false - A or V\nlet c;\nanswer.position = [{}]\n    if (answer.flag === \"A\") {\n        let degreesN = Number(elements[0].substr(13,2))\n        let minutesN = Number(elements[0].substr(15,7))\n        let ns = elements[0].substr(22,1)                                            // N or S\n        let degreesE = Number(elements[0].substr(23,3))\n        let minutesE = Number(elements[0].substr(26,7))\n        let ew = elements[0].substr(33,1)                                         // E or W\n        answer.position[0].latitude = degreesN + minutesN/60                         // 2232.9806N\n        if (ns === \"S\") answer.latitude = -answer.latitude\n        answer.position[0].longitude = degreesE + minutesE/60\n        if (ew === \"W\") answer.longitude = -answer.longitude        //11404.9355E\n}\n\nanswer.speedMoving = elements[0].substr(34,5)                                                                   // 000.1\nanswer.angleDirection = elements[0].substr(45,6)                                                                // 323.87\nanswer.signalStrength = elements[0].substr(51,3)                                                                // 060\nanswer.satellites = elements[0].substr(54,3)                                                                    // 009\nanswer.batteryLevel = elements[0].substr(57,3)                                                                  // 080\n// LBS datas\nanswer.mobileCountryCode = elements[1]                                                                          // 460\nanswer.mobileNetworkCode = elements[2]                                                                          // 0\nanswer.locationAreaCode = elements[3]                                                                           // 9520       \nanswer.cellId = elements[4]                                                                                     // 3671\n// WIFI bases only with flag = else\nlet i;\nanswer.wifiAccessPoints = []\n    if (answer.flag === \"V\") {\n        let wifiAccessPointsStrings = elements[5].split(\"&\")\n        let j;\n        for (j = 0; j < wifiAccessPointsStrings.length; j++) {\n            let baseElements = wifiAccessPointsStrings[j].split(\"|\")\n            answer.wifiAccessPoints.push({ ssid: baseElements[0], macAddress: baseElements[1], signalStrength: baseElements[2] })  // Home|74-DE-2B-44-88-8C|97&Home1|74-DE-2B-44-88-8C|97&Home2|74-DE-2B-44-88-8C|97&Home3|74-DE-2B-44-88-8C|97\n    }\n    // adjust baseCountwifiAccessPoints just in case the number actually there didn't match that expexted\n    answer.baseCountwifiAccessPoints = answer.wifiAccessPoints.length\n}\n\nmsg.payload = answer\nreturn msg","outputs":1,"noerr":0,"x":284.00001525878906,"y":180.00000190734863,"wires":[["c13430c8.a9858"]]},{"id":"c13430c8.a9858","type":"switch","z":"a2c38421.d88cc8","name":"Answer option","property":"payload.flag","propertyType":"msg","rules":[{"t":"eq","v":"A","vt":"str"},{"t":"eq","v":"V","vt":"str"}],"checkall":"true","repair":true,"outputs":2,"x":304.0000305175781,"y":223.19997787475586,"wires":[["757b61b5.efe8c","1bcaa80a.12c1e8"],["4952b8ec.6ff768","63ef6c3.61cdf94"]]},{"id":"20abe4e3.1cf5bc","type":"http request","z":"a2c38421.d88cc8","name":"MOZILLA MLS REQUEST","method":"use","ret":"txt","url":"","tls":"","x":548.8000602722168,"y":311.00005435943604,"wires":[["439d86fe.e4f568","fdd0a86e.07ebe8"]]},{"id":"4952b8ec.6ff768","type":"function","z":"a2c38421.d88cc8","name":"MLS LBS+WIFI","func":"// Get positions from wifiAccessPoints\n// var dev_url = \"https://location.services.mozilla.com/v1/geolocate?key=test\";\nvar dev_url = \"https://location.services.mozilla.com/v1/search?key=test\";\nvar data =\n{\n    \"cellTowers\": [{\n        \"mobileCountryCode\": msg.mobileCountryCode,\n        \"mobileNetworkCode\": msg.mobileNetworkCode,\n        \"locationAreaCode\": msg.locationAreaCode,\n        \"cellId\": msg.cellId,\n    }],\n    \"considerIp\": \"false\",\n    \"wifiAccessPoints\": msg.payload.wifiAccessPoints,\n    \"fallbacks\": {\n        \"lacf\": true,\n        \"ipf\": true\n    }\n}\nvar msg = {\n    \"method\" : \"POST\",\n    \"url\" : dev_url,\n    \"headers\" : {\n        \"Content-Type\": \"application/json\",\n    },\n    \"payload\" : JSON.stringify(data)\n};\n \nreturn msg\n","outputs":1,"noerr":0,"x":509.00006103515625,"y":277.00000381469727,"wires":[["20abe4e3.1cf5bc","dfc2e866.70ba28"]]},{"id":"46973628.79ef38","type":"inject","z":"a2c38421.d88cc8","name":"invalid_test","topic":"","payload":"IWAP01190215V0000.0000N00000.0000E000.1061830323.8706000908000102,226,10,1440,22327,HOTSPOT|D0:60:8C:E2:C0:9E|47&Cioco|58:6D:8F:49:42:4E|81&Cosmin-Land|14:CC:20:8A:18:50|91&Tavi-home|0C:9D:92:4C:14:38|93#","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":86,"y":156.00000190734863,"wires":[["92723490.c5de38"]]},{"id":"439d86fe.e4f568","type":"json","z":"a2c38421.d88cc8","name":"","property":"payload","action":"","pretty":false,"x":478.30001068115234,"y":343.6000061035156,"wires":[["929c3056.20e3b","9ada6b71.f59a28"]]},{"id":"929c3056.20e3b","type":"function","z":"a2c38421.d88cc8","name":"CONVERT TO WORLDMAP","func":"var msg1 = {};\n\nmsg1.payload=msg.payload;\n\nmsg1.payload.lat=msg.payload.lat;\n\nmsg1.payload.lon=msg.payload.lon;\n\ndelete msg.payload.position;\n\nmsg1.payload.name=\"F08\";\n\nmsg1.payload.icon = \"map-pin\";\n\nmsg1.payload.iconColor = \"orange\";\n\nmsg1.payload.radius=msg.payload.accuracy;\n\nmsg1.payload.date=Date().toString();\n\nreturn msg1;\n","outputs":1,"noerr":0,"x":548.0000114440918,"y":373.0000066757202,"wires":[["139c0613.3bd11a","654ee7b6.386d78"]]},{"id":"139c0613.3bd11a","type":"worldmap","z":"a2c38421.d88cc8","name":"","lat":"","lon":"","zoom":"","layer":"OSM","cluster":"","maxage":"","usermenu":"show","layers":"show","panit":"false","panlock":"false","zoomlock":"false","path":"/worldmap","x":861.3000144958496,"y":221.2000026702881,"wires":[]},{"id":"654ee7b6.386d78","type":"debug","z":"a2c38421.d88cc8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":781.3000106811523,"y":378.20000648498535,"wires":[]},{"id":"757b61b5.efe8c","type":"debug","z":"a2c38421.d88cc8","name":"S1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":526.4000072479248,"y":201.00000286102295,"wires":[]},{"id":"8d13887b.6381b8","type":"http request","z":"a2c38421.d88cc8","name":"MOZILLA MLS REQUEST","method":"use","ret":"txt","url":"","tls":"","x":561,"y":99,"wires":[["de87b490.df3758","8837032b.3389c"]]},{"id":"1bcaa80a.12c1e8","type":"function","z":"a2c38421.d88cc8","name":"MLS GPS+LBS","func":"// Get positions from GPS & LBS\n\nvar dev_url = \"https://location.services.mozilla.com/v1/search?key=test\";\nvar data =\n{\n   \"position\": {\n        \"latitude\": msg.payload.latitude,\n        \"longitude\": msg.payload.longitude,\n        \"heading\": msg.payload.angleDirection,\n        \"speed\": msg.payload.speedMoving,\n    }, \n    \"cellTowers\": [{\n        \"mobileCountryCode\": msg.payload.mobileCountryCode,\n        \"mobileNetworkCode\": msg.payload.mobileNetworkCode,\n        \"locationAreaCode\": msg.payload.locationAreaCode,\n        \"cellId\": msg.payload.cellId,\n    }],\n}\nvar msg = {\n    \"method\" : \"POST\",\n    \"url\" : dev_url,\n    \"headers\" : {\n        \"Content-Type\": \"application/json\",\n    },\n    \"payload\" : JSON.stringify(data)\n};\n \nreturn msg\n","outputs":1,"noerr":0,"x":521.2000007629395,"y":64.99994945526123,"wires":[["6cfb8868.e9b758","8d13887b.6381b8"]]},{"id":"de87b490.df3758","type":"json","z":"a2c38421.d88cc8","name":"","property":"payload","action":"","pretty":false,"x":490.49995040893555,"y":131.5999517440796,"wires":[["7833937b.85a74c","84041e88.c345b"]]},{"id":"7833937b.85a74c","type":"function","z":"a2c38421.d88cc8","name":"CONVERT TO WORLDMAP","func":"var msg1 = {};\n\nmsg1.payload=msg.payload;\n\nmsg1.payload.lon=msg.payload.lon;\n\nmsg1.payload.lat=msg.payload.lat;\n\ndelete msg.payload.position;\n\nmsg1.payload.name=\"F08\";\n\nmsg1.payload.icon = \"map-pin\";\n\nmsg1.payload.iconColor = \"orange\";\n\nmsg1.payload.radius=msg.payload.accuracy;\n\nmsg1.payload.date=Date().toString();\n\nreturn msg1;\n","outputs":1,"noerr":0,"x":560.199951171875,"y":160.99995231628418,"wires":[["22353a5c.ea0e46","139c0613.3bd11a"]]},{"id":"6cfb8868.e9b758","type":"debug","z":"a2c38421.d88cc8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":768.0000114440918,"y":67.00000071525574,"wires":[]},{"id":"8837032b.3389c","type":"debug","z":"a2c38421.d88cc8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":769.0000076293945,"y":99.00000190734863,"wires":[]},{"id":"84041e88.c345b","type":"debug","z":"a2c38421.d88cc8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":768,"y":132,"wires":[]},{"id":"22353a5c.ea0e46","type":"debug","z":"a2c38421.d88cc8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":767.0000076293945,"y":162.00000190734863,"wires":[]},{"id":"dfc2e866.70ba28","type":"debug","z":"a2c38421.d88cc8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":778.0000076293945,"y":277.00000381469727,"wires":[]},{"id":"fdd0a86e.07ebe8","type":"debug","z":"a2c38421.d88cc8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":778.0000038146973,"y":311.0000009536743,"wires":[]},{"id":"9ada6b71.f59a28","type":"debug","z":"a2c38421.d88cc8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":778.0000114440918,"y":344.0000057220459,"wires":[]},{"id":"63ef6c3.61cdf94","type":"debug","z":"a2c38421.d88cc8","name":"S2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":526.0000076293945,"y":235.00000381469727,"wires":[]}]
#2

Not sure what you mean - the accuracy is what you are getting back from your call so it looks ok to me.
Maybe set the clustering to 0 (off) in the worldmap so you can see both the pointer and ring

#3

I will try.

Thanks dceejay!!!