# How to fix the locations in worldmap

**URL:** <https://discourse.nodered.org/t/how-to-fix-the-locations-in-worldmap/7495>\
**Category:** General\
**Created:** [1 February 2019 19:21 UTC](https://discourse.nodered.org/t/how-to-fix-the-locations-in-worldmap/7495 "2019-02-01T19:21:53Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![emspe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/emspe/32/5421_2.png) [@emspe](https://discourse.nodered.org/u/emspe)\
**Post date:** [1 February 2019 19:21 UTC](https://discourse.nodered.org/t/how-to-fix-the-locations-in-worldmap/7495/1 "2019-02-01T19:21:53Z")

</div>

Hello,

I have marked several locations in worldmap by injecting and simple function containing properties like lon,lat,icon etc. I defined those objects as global variables since I wanna change their color with external decisions later on. Also I was able to add that map to dashboard.

Where I face hard for me to solve is to keep those locations fix through out the project. Now when i refresh the worldmap or the dashboard all the locations get lost. I have to re-inject them again.

Instead of injecting what is the best method to mark the locations in worldmap which will last through out the project ? Kindly help me.

Thank you.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [1 February 2019 20:56 UTC](https://discourse.nodered.org/t/how-to-fix-the-locations-in-worldmap/7495/2 "2019-02-01T20:56:35Z")

</div>

the `worldmap in` node provides events when client connect, disconnect, click on markers etc... The connect event can be used to trigger your flow to resend markers to set them up as you wish.

---

<div class="post-metadata">

**Author:** ![emspe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/emspe/32/5421_2.png) [@emspe](https://discourse.nodered.org/u/emspe)\
**Post date:** [3 February 2019 16:19 UTC](https://discourse.nodered.org/t/how-to-fix-the-locations-in-worldmap/7495/3 "2019-02-03T16:19:17Z")

</div>

Hi ,

I'm sorry this is not clear. What I used was the **worldmap** node only.

thank you for introducing the **woirldmap in** node which I have forgotten. I will try it.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [3 February 2019 16:31 UTC](https://discourse.nodered.org/t/how-to-fix-the-locations-in-worldmap/7495/4 "2019-02-03T16:31:44Z")

</div>

Mixing this with your other thread... I would use something like this - to feed the worldmap node.

```auto
[{"id":"94d4bb1f.9ba388","type":"function","z":"8eaef9ed.138468","name":"Add SS1","func":"var SS1 = {\n name:\"SS1 : Kurunegala\", \n lat:7.486944, \n lon:80.365045,\n icon:\"tag\",\n iconColor:\"dark\",\n extrainfo:\"Hello ! this is station 1\"\n};\nmsg.payload = SS1;\n\nreturn msg;","outputs":1,"noerr":0,"x":400,"y":360,"wires":[["b3b8baae.2865a8","ff59e95a.55d8e8"]]},{"id":"11aa64ec.18e4bb","type":"worldmap in","z":"8eaef9ed.138468","name":"","path":"/worldmap","x":100,"y":360,"wires":[["1c0dc03c.c30ec"]]},{"id":"1c0dc03c.c30ec","type":"switch","z":"8eaef9ed.138468","name":"","property":"payload.action","propertyType":"msg","rules":[{"t":"eq","v":"connected","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":250,"y":360,"wires":[["94d4bb1f.9ba388"]]}]

```

---

<div class="post-metadata">

**Author:** ![emspe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/emspe/32/5421_2.png) [@emspe](https://discourse.nodered.org/u/emspe)\
**Post date:** [3 February 2019 17:37 UTC](https://discourse.nodered.org/t/how-to-fix-the-locations-in-worldmap/7495/5 "2019-02-03T17:37:29Z")

</div>

Well...I got it. 😃  
I learnt another new thing. Thank you very much again 😌

---

<div class="post-metadata">

**Author:** ![alex1](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@alex1](https://discourse.nodered.org/u/alex1)\
**Post date:** [2 April 2019 11:04 UTC](https://discourse.nodered.org/t/how-to-fix-the-locations-in-worldmap/7495/6 "2019-04-02T11:04:19Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/6427d2a9690e0080f3b94754f5a803d37a4f5780.png)

Doing like this?But this is when i fixed the location myself. What if the location is provided by other user? in which the location is changing.

---

<div class="post-metadata">

**Author:** ![alex1](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@alex1](https://discourse.nodered.org/u/alex1)\
**Post date:** [2 April 2019 11:07 UTC](https://discourse.nodered.org/t/how-to-fix-the-locations-in-worldmap/7495/7 "2019-04-02T11:07:34Z")

</div>

And the injection only once. not repeatedly

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [2 April 2019 12:24 UTC](https://discourse.nodered.org/t/how-to-fix-the-locations-in-worldmap/7495/8 "2019-04-02T12:24:07Z")

</div>

not sure what you mean ? if you send a new msg with the same name but new lat and lon it will update the position.

---

<div class="post-metadata">

**Author:** ![alex1](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@alex1](https://discourse.nodered.org/u/alex1)\
**Post date:** [2 April 2019 15:03 UTC](https://discourse.nodered.org/t/how-to-fix-the-locations-in-worldmap/7495/9 "2019-04-02T15:03:10Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/9/9909e82e16b91f19fcd55f028d13b298d4d40a59.png)  
previously im using this, but the marker will be gone after i refresh the map

---

<div class="post-metadata">

**Author:** ![alex1](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@alex1](https://discourse.nodered.org/u/alex1)\
**Post date:** [2 April 2019 15:06 UTC](https://discourse.nodered.org/t/how-to-fix-the-locations-in-worldmap/7495/10 "2019-04-02T15:06:56Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/6d1a12d03c9d85a8d7c3bb9fe51082e3c6292bed.png)  
This is the solution that you have provided right? so that the marker will not be gone after refresh.  
But how to use this flow? do i need to add anything after the function "Add SS1"?

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [2 April 2019 15:36 UTC](https://discourse.nodered.org/t/how-to-fix-the-locations-in-worldmap/7495/11 "2019-04-02T15:36:26Z")

</div>

I have no idea what you are trying to do - so maybe yes - maybe no - certainly it will probably need to go to a worldmap out node.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [2 April 2019 15:38 UTC](https://discourse.nodered.org/t/how-to-fix-the-locations-in-worldmap/7495/12 "2019-04-02T15:38:26Z")

</div>

The idea is to look at what `worldmap-in` returns. If msg.payload.action is 'connected' send what you want to show on the map to the `worldmap` node.

This will cause the information to display whenyou first open the map and when someone refreshes the browser.

---

<div class="post-metadata">

**Author:** ![alex1](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@alex1](https://discourse.nodered.org/u/alex1)\
**Post date:** [3 April 2019 02:34 UTC](https://discourse.nodered.org/t/how-to-fix-the-locations-in-worldmap/7495/13 "2019-04-03T02:34:15Z")

</div>

if im using the flow provided by you. Does that mean i can only insert the location using this function node?  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/6ae8dae7651012020c5df7152c0f58249ef0db91.png)

---

<div class="post-metadata">

**Author:** ![alex1](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@alex1](https://discourse.nodered.org/u/alex1)\
**Post date:** [3 April 2019 02:41 UTC](https://discourse.nodered.org/t/how-to-fix-the-locations-in-worldmap/7495/14 "2019-04-03T02:41:36Z")

</div>

My problem is that now i have 1 main nodered server. All the other node-red server can send the location data to my main nodered server through MQTT cloud. But I dont know what is the location, might be US, canada or somewhere else. Meaning im not able to determine their location. My main nodered server is mainly doing the monitoring of the worldmap. If anything happen, people from other country can send their location to me through MQTT cloud and a marker should appear at my worldmap. But the problem here is that whenever i refresh my worldmap...all the pop up, markers will be gone. How can i solve this problem?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [3 April 2019 04:52 UTC](https://discourse.nodered.org/t/how-to-fix-the-locations-in-worldmap/7495/15 "2019-04-03T04:52:59Z")

</div>

How about storing the information in a database then replace that function node with a call to the database to read everything and then have a function node build all the info to display and then send it to the world map

---

<div class="post-metadata">

**Author:** ![panban-ux](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/panban-ux/32/21609_2.png) [@panban-ux](https://discourse.nodered.org/u/panban-ux)\
**Post date:** [5 June 2020 12:17 UTC](https://discourse.nodered.org/t/how-to-fix-the-locations-in-worldmap/7495/16 "2020-06-05T12:17:18Z")

</div>

so to retain the markers after a refresh or open the map, should i implement a switch node after my funtion and the to world map in? cos it doesnt work, after refresh i cant retain my points.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [5 June 2020 12:38 UTC](https://discourse.nodered.org/t/how-to-fix-the-locations-in-worldmap/7495/17 "2020-06-05T12:38:14Z")

</div>

where and how to save your points is up to you. You can use the worldmap-in node to detect a new client connecting (or refreshing) and use that to trigger resending whatever points you like.

---

<div class="post-metadata">

**Author:** ![panban-ux](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/panban-ux/32/21609_2.png) [@panban-ux](https://discourse.nodered.org/u/panban-ux)\
**Post date:** [5 June 2020 12:49 UTC](https://discourse.nodered.org/t/how-to-fix-the-locations-in-worldmap/7495/18 "2020-06-05T12:49:28Z")

</div>

> [@dceejay](#):
>
> how to save your points is up to you. You can use the worldmap-in node to detect a new client connecting (or refreshing) and use that to trigger resending whatever points you like.

I've placed a worldmap in but nothing, what do you mean to detect a new client, should not be connected to the current flow?

 ![Untitled](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/b/cb453465c60d5c8c09ebcbd0f6d1488620d4ddd5.png)

The flow in question

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [5 June 2020 14:25 UTC](https://discourse.nodered.org/t/how-to-fix-the-locations-in-worldmap/7495/19 "2020-06-05T14:25:13Z")

</div>

The tracks node is not a store. It holds tracks per each marker sent - so needs the name of a marker in order to be added to the track (and thus trigger it to send out the track). The connect message is just a trigger - you still need to tell it which points to (re)plot.

---

<div class="post-metadata">

**Author:** ![panban-ux](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/panban-ux/32/21609_2.png) [@panban-ux](https://discourse.nodered.org/u/panban-ux)\
**Post date:** [8 June 2020 17:20 UTC](https://discourse.nodered.org/t/how-to-fix-the-locations-in-worldmap/7495/21 "2020-06-08T17:20:37Z")

</div>

> [@dceejay](#):
>
> The connect message is just a trigger - you still need to tell it which points to (re)plot.

Will i have to include inside the switch string? as per below

 ![1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/5/b5e35653e749ae72e9d98a749745b4f3c92e0bb0.png)

the whole function thats under the ttgo1 function??

 ![2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/3/c3289f9e77b7425bfd86066ceddb8d65ad88f359.png)

For example what i asked is to retain the last position of that car marker after a new user open his browser

 ![3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/5/7573996d2c178391cb831a49bde9b9a12ae94a8a.jpeg)

What i get instead is when refreshing in debug  
08/06/2020, 20:18:43[node: ttgo1]function : (error)

"TypeError: Cannot read property 'latitude' of undefined"  
What property and where should i edit for this?  
Thanks in advance

[Next page](https://discourse.nodered.org/t/how-to-fix-the-locations-in-worldmap/7495.md?page=2)
