how to calculate the distance between two coodinates

1,150 views
Skip to first unread message

Chen Chen

unread,
Sep 18, 2014, 3:33:19 AM9/18/14
to node...@googlegroups.com
Hi everyone,

Did u use owntracks on node-red? i would like to calculate the distance between two owntracks users but don't know what can i write in the function.


chris mobberley

unread,
Sep 18, 2014, 4:29:28 AM9/18/14
to node...@googlegroups.com
Hi,

http://flows.nodered.org/ - Contains a few exmaples of using own-tracks via MQTT. I know of atleast one flow on there which uses geofence and would probably be an excellent starting point for this.

http://flows.nodered.org/flow/ab31cd939f2e73503fb0 <-- Specific example - The function nodes are probably most interesting for you on there.

Ang Eleanor

unread,
Sep 18, 2014, 4:41:00 AM9/18/14
to node...@googlegroups.com
@chrismobberley

Hi, we are looking for any java programming codes that can actually help us to calculate the two distance of owntracks when they are away from each other using the function node.

Mark Setrem

unread,
Sep 18, 2014, 6:31:15 AM9/18/14
to node...@googlegroups.com

Have you tried using Google?

The maths to calculate the distance between two pairs of lat long coordinates is fairly straight forward and easily found online.  As Chris says there are several flows within http://flows.nodered.org that should help you in how to structure the flow.

One thing you will need to do is store the values of one pair of lat, longs and trigger the calculation when the other pair arrives.

There are examples of doing this in the forum.






Claudiu O

unread,
Sep 18, 2014, 11:07:42 AM9/18/14
to node...@googlegroups.com
If you are looking for Java code, you could use this library: https://code.google.com/p/simplelatlng/ It is not mine, just something I found and used in the past with great results.

TJ Koury

unread,
Sep 18, 2014, 11:48:53 AM9/18/14
to node...@googlegroups.com
You're looking for this:


Implemented like this:


Simplified like this:

dlon = lon2 - lon1 
dlat = lat2 - lat1 
a = (sin(dlat/2))^2 + cos(lat1) * cos(lat2) * (sin(dlon/2))^2 
c = 2 * atan2( sqrt(a), sqrt(1-a) ) 
d = R * c (where R is the radius of the Earth)

Dave C-J

unread,
Sep 18, 2014, 12:11:35 PM9/18/14
to node...@googlegroups.com
If this is for a Node-RED function then you will want javascript not java.... 
and Google is your friend - try searching for
    javascript distance between lat lon

Reply all
Reply to author
Forward
0 new messages