File tree 3 files changed +21
-5
lines changed
3 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,11 @@ To convert position to words it requires
27
27
- ` msg.location.lat `
28
28
- ` msg.location.lon `
29
29
30
+ or
31
+
32
+ - ` msg.payload.lat `
33
+ - ` msg.payload.lon `
34
+
30
35
or
31
36
32
37
- ` msg.payload ` containing a string lat,lon
@@ -36,6 +41,8 @@ To convert words to position it requires
36
41
37
42
- ` msg.payload ` containing a string of _ unique.three.words_
38
43
44
+ A 3 word string separated by dots.
45
+
39
46
40
47
The API-key is stored in a separate credentials file.
41
48
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " node-red-node-what3words" ,
3
- "version" : " 0.0.5 " ,
3
+ "version" : " 0.0.7 " ,
4
4
"description" : " A Node-RED node to convert locations to/from what3words" ,
5
5
"dependencies" : {
6
6
"geo.what3words" : " ^2.0.0"
Original file line number Diff line number Diff line change @@ -12,10 +12,19 @@ module.exports = function(RED) {
12
12
var w1 = / ^ \* \w { 6 , 31 } $ / ;
13
13
var w3 = / ^ \w + \. \w + \. \w + $ / ;
14
14
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 } )
19
28
. then ( function ( response ) {
20
29
msg . payload = response ; // prom.cape.pump
21
30
if ( ! msg . hasOwnProperty ( "topic" ) || ( msg . topic === "" ) ) { msg . topic = "what3words" ; }
You can’t perform that action at this time.
0 commit comments