Skip to content

Commit 3e8353f

Browse files
author
Dave Conway-Jones
committed
bump waht3words package
add msg.payload{lat:lon} option
1 parent 2f14b17 commit 3e8353f

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

parsers/what3words/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ To convert position to words it requires
2727
- `msg.location.lat`
2828
- `msg.location.lon`
2929

30+
or
31+
32+
- `msg.payload.lat`
33+
- `msg.payload.lon`
34+
3035
or
3136

3237
- `msg.payload` containing a string lat,lon
@@ -36,6 +41,8 @@ To convert words to position it requires
3641

3742
- `msg.payload` containing a string of _unique.three.words_
3843

44+
A 3 word string separated by dots.
45+
3946

4047
The API-key is stored in a separate credentials file.
4148

parsers/what3words/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name" : "node-red-node-what3words",
3-
"version" : "0.0.5",
3+
"version" : "0.0.7",
44
"description" : "A Node-RED node to convert locations to/from what3words",
55
"dependencies" : {
66
"geo.what3words" : "^2.0.0"

parsers/what3words/what3words.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,19 @@ module.exports = function(RED) {
1212
var w1 = /^\*\w{6,31}$/;
1313
var w3 = /^\w+\.\w+\.\w+$/;
1414
this.on("input", function(msg) {
15-
if (msg.hasOwnProperty("location")) {
16-
var lat = msg.location.lat;
17-
var lon = msg.location.lon;
18-
node.w3w.positionToWords({ position:lat + "," + lon, lang:node.lang })
15+
if (msg.hasOwnProperty("location") && msg.location.hasOwnProperty("lat") && msg.location.hasOwnProperty("lon")) {
16+
node.w3w.positionToWords({ position:msg.location.lat + "," + msg.location.lon, lang:node.lang })
17+
.then(function(response) {
18+
msg.payload = response; // prom.cape.pump
19+
if (!msg.hasOwnProperty("topic") || (msg.topic === "")) { msg.topic = "what3words"; }
20+
node.send(msg);
21+
})
22+
.catch(function(err) {
23+
node.warn(err)
24+
});
25+
}
26+
else if (msg.hasOwnProperty("payload") && msg.payload.hasOwnProperty("lat") && msg.payload.hasOwnProperty("lon")) {
27+
node.w3w.positionToWords({ position:msg.payload.lat + "," + msg.payload.lon, lang:node.lang })
1928
.then(function(response) {
2029
msg.payload = response; // prom.cape.pump
2130
if (!msg.hasOwnProperty("topic") || (msg.topic === "")) { msg.topic = "what3words"; }

0 commit comments

Comments
 (0)