# Removing negative latitude and longitude coordinates

**URL:** <https://discourse.nodered.org/t/removing-negative-latitude-and-longitude-coordinates/34665>\
**Category:** General\
**Created:** [22 October 2020 08:45 UTC](https://discourse.nodered.org/t/removing-negative-latitude-and-longitude-coordinates/34665 "2020-10-22T08:45:36Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![bachloo.rahul](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@bachloo.rahul](https://discourse.nodered.org/u/bachloo.rahul)\
**Post date:** [22 October 2020 08:45 UTC](https://discourse.nodered.org/t/removing-negative-latitude-and-longitude-coordinates/34665/1 "2020-10-22T08:45:37Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/4/349576784a99ed29914f3f613b7a33819a083678.png)  
My Gps Sensor is sending 2 payloads of messages containing latitude and longitude at the same time.So want to remove the extra latitude and longitude coordinates.  
Here is the flow  
[flows.json](https://discourse.nodered.org/uploads/short-url/ulnIczsWZ7EHZQXIPRclIPOl1KD.json) (632 Bytes)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/e/aeff50b23e92ba7b147f2e9b4399208885d2af3f.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [22 October 2020 09:12 UTC](https://discourse.nodered.org/t/removing-negative-latitude-and-longitude-coordinates/34665/2 "2020-10-22T09:12:09Z")

</div>

When posting a flow please use the `</>` button at the top of the edit window and paste the flow in.

Are there two messages coming out of the MQTT node?

---

<div class="post-metadata">

**Author:** ![bachloo.rahul](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@bachloo.rahul](https://discourse.nodered.org/u/bachloo.rahul)\
**Post date:** [22 October 2020 09:14 UTC](https://discourse.nodered.org/t/removing-negative-latitude-and-longitude-coordinates/34665/3 "2020-10-22T09:14:28Z")

</div>

yes collin 2 messages are coming from mqtt node.the first coordintes are correct as you can see on map.{"lat":28.39207763671875,"lon":76.95928548177083,"name":"apple","icon":"fa-truck","layer":"marker"}

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/1/1167f88edd8f981b4045868f05e14fd78345215c.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [22 October 2020 09:19 UTC](https://discourse.nodered.org/t/removing-negative-latitude-and-longitude-coordinates/34665/4 "2020-10-22T09:19:12Z")

</div>

How are they getting into mqtt?

---

<div class="post-metadata">

**Author:** ![bachloo.rahul](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@bachloo.rahul](https://discourse.nodered.org/u/bachloo.rahul)\
**Post date:** [22 October 2020 09:22 UTC](https://discourse.nodered.org/t/removing-negative-latitude-and-longitude-coordinates/34665/5 "2020-10-22T09:22:08Z")

</div>

from gps tracker-\>gateway-\>mqtt broker(cloud)-\>node red mqtt subscribe node.  
basically gps tracker is sending 2 packets each time its send.the first one is correct and second one is some absurd value.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [22 October 2020 09:26 UTC](https://discourse.nodered.org/t/removing-negative-latitude-and-longitude-coordinates/34665/6 "2020-10-22T09:26:45Z")

</div>

Is there some way that you can tell by looking at the values that they are absurd? In the first image I see it has an illegal lon value, but the second image has lat 6, lon -1.3 which is not intrinsically absurd. If you can say how you know that it is absurd then you can use a switch node to only pass valid ones.

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [22 October 2020 09:30 UTC](https://discourse.nodered.org/t/removing-negative-latitude-and-longitude-coordinates/34665/7 "2020-10-22T09:30:14Z")

</div>

Maybe if you put debug node to somewhere earlier in that flow, there might be more info about the message content which can then be used as filter

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [22 October 2020 09:33 UTC](https://discourse.nodered.org/t/removing-negative-latitude-and-longitude-coordinates/34665/8 "2020-10-22T09:33:14Z")

</div>

Alternatively if it is always the second one that is to be discarded and it always appears within a short time of the first one then you could use a Trigger node set to send the message immediately then after, say 5 seconds, send nothing and with Extend Delay checked so that it will throw away an message appearing with 5 seconds of the first one.

---

<div class="post-metadata">

**Author:** ![bachloo.rahul](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@bachloo.rahul](https://discourse.nodered.org/u/bachloo.rahul)\
**Post date:** [22 October 2020 09:38 UTC](https://discourse.nodered.org/t/removing-negative-latitude-and-longitude-coordinates/34665/9 "2020-10-22T09:38:49Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/f/3f496c3d387d509878c698249f509b1c44748135.png)  
how to set trigger node so that message 2nd can be discarded after a time interval of 5 sec or so.?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [22 October 2020 09:50 UTC](https://discourse.nodered.org/t/removing-negative-latitude-and-longitude-coordinates/34665/10 "2020-10-22T09:50:17Z")

</div>

You should set 'then send' to Nothing (it is one of the dropdown options), as you have it it will send a message with a payload of "0". Also you have the delay set to 250 msec rather than 5 seconds.

---

<div class="post-metadata">

**Author:** ![bachloo.rahul](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@bachloo.rahul](https://discourse.nodered.org/u/bachloo.rahul)\
**Post date:** [22 October 2020 10:06 UTC](https://discourse.nodered.org/t/removing-negative-latitude-and-longitude-coordinates/34665/11 "2020-10-22T10:06:37Z")

</div>

this is the output

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/7/87158a3e1aa74914dc01427c2f5f45323a42b29a.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [22 October 2020 10:22 UTC](https://discourse.nodered.org/t/removing-negative-latitude-and-longitude-coordinates/34665/12 "2020-10-22T10:22:21Z")

</div>

The "0" is because you haven't changed the Then Send setting as I said. Also put the trigger on the output of the mqtt, there is no point feeding it through all the other nodes then discarding it. However, before doing that can you put the debug on the mqtt node and show us exactly what is coming out of that please?

---

<div class="post-metadata">

**Author:** ![bachloo.rahul](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@bachloo.rahul](https://discourse.nodered.org/u/bachloo.rahul)\
**Post date:** [22 October 2020 10:30 UTC](https://discourse.nodered.org/t/removing-negative-latitude-and-longitude-coordinates/34665/13 "2020-10-22T10:30:37Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/7/17112d9721bd8014ef79aba82c48c448f15befb4.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/5/a5ffba16027892434d51e27d5039e7fdc0a9c9b5.png)  
This is the output when debud node placed after mqtt node.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [22 October 2020 10:34 UTC](https://discourse.nodered.org/t/removing-negative-latitude-and-longitude-coordinates/34665/14 "2020-10-22T10:34:53Z")

</div>

Those have got lat and lon as 0.  
Also why do you not just set the output of mqtt node to parsed json and then you will get the values directly in a javascript object? No need for the base64 and buffer parser unless I am missing something.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [22 October 2020 10:38 UTC](https://discourse.nodered.org/t/removing-negative-latitude-and-longitude-coordinates/34665/15 "2020-10-22T10:38:39Z")

</div>

Sorry, I am still getting back up to speed. Been away for 2 weeks.

Dumb question: Why do you want to remove the `-` number/s from the longitude values?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [22 October 2020 10:40 UTC](https://discourse.nodered.org/t/removing-negative-latitude-and-longitude-coordinates/34665/16 "2020-10-22T10:40:27Z")

</div>

> [@Trying\_to\_learn](#):
>
> Why do you want to remove the `-` number/s from the longitude values?

He/she is trying to get rid of what appear to be faulty position values, but I am not convinced they are there in the existing data which is why we are looking at what is coming out of the MQTT need before working out what the solution is.

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [22 October 2020 10:42 UTC](https://discourse.nodered.org/t/removing-negative-latitude-and-longitude-coordinates/34665/17 "2020-10-22T10:42:36Z")

</div>

Seems to me that you have 2 data packets and they carry different information.

[http://doc.mokotechnology.com/index.php?s=/2&page\_id=11](http://doc.mokotechnology.com/index.php?s=/2&page_id=11).

The first one holds location data, the second one has movement and battery info in it. But to make sure which one you have currently in processing, it can be read out from that binary.  
So read the doc and follow the rules.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [22 October 2020 10:43 UTC](https://discourse.nodered.org/t/removing-negative-latitude-and-longitude-coordinates/34665/18 "2020-10-22T10:43:31Z")

</div>

Thanks.

I maybe should have looked deeper into the thread.

I believe you are correct. It seems there are extraneous packets in there.

Correct:  
Determining from where they are coming would be better.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [22 October 2020 10:44 UTC](https://discourse.nodered.org/t/removing-negative-latitude-and-longitude-coordinates/34665/19 "2020-10-22T10:44:54Z")

</div>

~~Maybe stick a `debug` node on the `MQTT IN` node and display the entire message.~~

I think I'll shut up. My brain is really not with me just now.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [22 October 2020 10:46 UTC](https://discourse.nodered.org/t/removing-negative-latitude-and-longitude-coordinates/34665/20 "2020-10-22T10:46:16Z")

</div>

How about you post the actual data rather than a screen shot?

[Next page](https://discourse.nodered.org/t/removing-negative-latitude-and-longitude-coordinates/34665.md?page=2)
