Apologies for the simple question. I know it will probably have a basic answer. I tried looking over the forum but I am sure I am not searching for the right thing.
I want to show a phone's position on a map. The map node requires this format:
{"name":"Joe", "lat":51, "lon":-1.05}
I am able to get the information I need with this code:
var lat = { payload: msg.payload.iPhone[1].locationInfo.latitude };
var long = { payload: msg.payload.iPhone[1].locationInfo.longitude };
var alt = { payload: msg.payload.iPhone[1].locationInfo.altitude };
return msg;
What I am failing to find out and thus learn how to do is how to write the return message so that the map node gets the information it needs. Any help would be appreciated. Glad for a point in the right direction. I have no coding experience.
var lat = msg.payload.iPhone[1].locationInfo.latitude;
var lon = msg.payload.iPhone[1].locationInfo.longitude;
var alt = msg.payload.iPhone[1].locationInfo.altitude;
msg.payload = {
"name":"Joe",
"lat":lat ,
"lon":lon,
"alt": alt
}
return msg;
Seems like I am getting really close but getting no icon on map yet. Just a quick question, do you think that because the lat and lon are objects has anything to do with it?.
I understand better now how to get information into the payload.
Code:
var lat = { payload: msg.payload.iPhone[1].locationInfo.latitude };
var lon = { payload: msg.payload.iPhone[1].locationInfo.longitude };
msg.payload = {
"name": "circle",
"lat": lat,
"lon": lon,
"icon": "bullseye",
"iconColor": '#931C29',
}
return msg;
Right!!. I missed this completely. Got excited about your answer and neglected to read carefully. Sorry. Thank you so much for your help and your time. It works perfectly now.
@Steve-Mcl I hope I am not taking advantage of your generosity. It is all working great except for displaying the battery level of an Apple Watch. I get this error:
TypeError: Cannot read property '2' of undefined
I am able to display battery level of phones which path is like this:
Worked!. Thank you so much again for all your help. Know enough to get started but not enough to get out of trouble. Like to learn by doing but get stuck sometimes. Much appreciated.
I recommend watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.