# Help for newbie

**URL:** https://discourse.nodered.org/t/help-for-newbie/41977
**Category:** Dashboard
**Created:** [3 March 2021 22:53 UTC](https://discourse.nodered.org/t/help-for-newbie/41977 "2021-03-03T22:53:14Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![patofoto](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/patofoto/32/25792_2.png) [@patofoto](https://discourse.nodered.org/u/patofoto)
#### Post date: [3 March 2021 22:53 UTC](https://discourse.nodered.org/t/help-for-newbie/41977/1 "2021-03-03T22:53:14Z")

</div>

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:

```auto

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.

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [3 March 2021 23:08 UTC](https://discourse.nodered.org/t/help-for-newbie/41977/2 "2021-03-03T23:08:41Z")

</div>

```auto
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;

```

---

<div class="post-metadata">

### Author: ![patofoto](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/patofoto/32/25792_2.png) [@patofoto](https://discourse.nodered.org/u/patofoto)
#### Post date: [3 March 2021 23:31 UTC](https://discourse.nodered.org/t/help-for-newbie/41977/3 "2021-03-03T23:31:54Z")

</div>

@Steve-Mcl Thank you very much. Will try soon.

---

<div class="post-metadata">

### Author: ![patofoto](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/patofoto/32/25792_2.png) [@patofoto](https://discourse.nodered.org/u/patofoto)
#### Post date: [3 March 2021 23:41 UTC](https://discourse.nodered.org/t/help-for-newbie/41977/4 "2021-03-03T23:41:57Z")

</div>

Getting this on the debug window:

![Screen Shot 2021-03-03 at 6.38.29 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/3/0355e4922ec7e8a839d3fee450fc6f7060f211d5.png)

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:

```auto
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;

```

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [3 March 2021 23:44 UTC](https://discourse.nodered.org/t/help-for-newbie/41977/5 "2021-03-03T23:44:11Z")

</div>

> [@patofoto](#):
>
> do you think that because the lat and lon are objects has anything to do with it

Yes.

~~Expand them, see where the real value is, then adjust the function to take them properties into the payload instead of their parent object.~~

scratch that ↑

Why did you put the values into objects?....

> [@patofoto](#):
>
> ```auto
> var lat = { payload: msg.payload.iPhone[1].locationInfo.latitude };
> var lon = { payload: msg.payload.iPhone[1].locationInfo.longitude };
> 
> ```

I gave you the working code...

> [@Steve-Mcl](#):
>
> ```auto
> var lat = msg.payload.iPhone[1].locationInfo.latitude;
> var lon = msg.payload.iPhone[1].locationInfo.longitude;
> 
> ```

---

<div class="post-metadata">

### Author: ![patofoto](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/patofoto/32/25792_2.png) [@patofoto](https://discourse.nodered.org/u/patofoto)
#### Post date: [4 March 2021 01:13 UTC](https://discourse.nodered.org/t/help-for-newbie/41977/6 "2021-03-04T01:13:31Z")

</div>

> [@Steve-Mcl](#):
>
> ```auto
> var lat = msg.payload.iPhone[1].locationInfo.latitude;
> var lon = msg.payload.iPhone[1].locationInfo.longitude;
> var alt = msg.payload.iPhone[1].locationInfo.altitude;
> 
> ```

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.

---

<div class="post-metadata">

### Author: ![patofoto](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/patofoto/32/25792_2.png) [@patofoto](https://discourse.nodered.org/u/patofoto)
#### Post date: [4 March 2021 20:52 UTC](https://discourse.nodered.org/t/help-for-newbie/41977/7 "2021-03-04T20:52:18Z")

</div>

@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:

```auto
TypeError: Cannot read property '2' of undefined

```

I am able to display battery level of phones which path is like this:

```auto
payload.iPhone[1].batteryLevel

```

But the watch's path is like this:

```auto
payload["Apple Watch"][2].batteryLevel

```

The gauge node for the watch looks this this now:

 ![Screen Shot 2021-03-04 at 3.48.22 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/c/9c2c0b15e07ac02de3071e89d11228f39ae70ec1.png)

because the node for the iPhone looks like this and it is working:

 ![Screen Shot 2021-03-04 at 3.50.23 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/4/747dcf4418ebd25a1943339ee99818de8982e2b1.png)

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [4 March 2021 20:55 UTC](https://discourse.nodered.org/t/help-for-newbie/41977/8 "2021-03-04T20:55:28Z")

</div>

show me a debug output containing these values (expand all properties)

---

<div class="post-metadata">

### Author: ![patofoto](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/patofoto/32/25792_2.png) [@patofoto](https://discourse.nodered.org/u/patofoto)
#### Post date: [4 March 2021 21:02 UTC](https://discourse.nodered.org/t/help-for-newbie/41977/9 "2021-03-04T21:02:22Z")

</div>

26 devices on the Apple Find Me node. expanded the one for the watch. Assume you don't want everything.

 ![Screen Shot 2021-03-04 at 4.00.15 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/b/8ba3137ddb2adae753eab3400f332c07c1687d20.png)

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [4 March 2021 21:07 UTC](https://discourse.nodered.org/t/help-for-newbie/41977/10 "2021-03-04T21:07:00Z")

</div>

Not sure why it doesnt work.

Instead, you can just move the values somewhere more accessible.

add a change node between set it to copy the values of interest to somewhere more sensible...

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/b/ab22f4b34150099981d23326a173dbf190a050ff.png)

then use {{batteryLevel}} and {{displayName}} in your ui items

---

<div class="post-metadata">

### Author: ![patofoto](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/patofoto/32/25792_2.png) [@patofoto](https://discourse.nodered.org/u/patofoto)
#### Post date: [4 March 2021 21:19 UTC](https://discourse.nodered.org/t/help-for-newbie/41977/11 "2021-03-04T21:19:48Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [4 March 2021 21:21 UTC](https://discourse.nodered.org/t/help-for-newbie/41977/12 "2021-03-04T21:21:05Z")

</div>

I recommend watching this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). 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.

---

<div class="post-metadata">

### Author: ![patofoto](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/patofoto/32/25792_2.png) [@patofoto](https://discourse.nodered.org/u/patofoto)
#### Post date: [4 March 2021 21:52 UTC](https://discourse.nodered.org/t/help-for-newbie/41977/13 "2021-03-04T21:52:58Z")

</div>

Wise advice. Will watch this weekend. Thank you again

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [3 April 2021 21:53 UTC](https://discourse.nodered.org/t/help-for-newbie/41977/14 "2021-04-03T21:53:24Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
