i need to find the distance between two gps location, So i think to do this:

  • lat1(seconds)-lat2(seconds)=lat * 30.7151 == distance latitude in meters =Latm

  • long1(seconds)-long2(seconds)=long *30.9221=== distance longitude in meters=Longm

for overall distance between them = sqr(Latm^2+Longm^2). note: the nodes are in range of 30 meters so i need to deal with seconds cause it is small scale.

  • It would help if you can add which software or programming language you are using to achieve this.
    – DotPi
    Apr 19, 2013 at 7:55
  • i use TinyOs programming for sensor nodes
    – H.H
    Apr 19, 2013 at 8:19

1 Answer 1


Euclidean distances don't make much sense when calculated from lat/long. Haversine formula is used to calculate distance between lat/long on the surface of the earth surface. If the distance between the two places in question is large please consider using Haversine formula. Some detail and a calculator for Haversine formula can be found at: http://www.movable-type.co.uk/scripts/latlong.html

If the places in question are not far apart, then you can convert the lat/long to UTM and then use the normal formula for Euclidean Distance:

  • in this link, i didn't know what this function ""atan2""
    – H.H
    Apr 19, 2013 at 8:23
  • atan2 is a function which is provided in most programming languages to calculate the arc-tangent between the 2 points; i.e the angle between 2 points. atan2 is special in the sense that it takes into account the signs of the inputs. I do not know whether the atan2 function is provided in TinyOS. If not atan2 can be implemented using normal arctangent function. Details about what the arctangent function is and how it can be implemented using atan can be found in the wikipedia page: en.wikipedia.org/wiki/Atan2 .
    – DotPi
    Apr 19, 2013 at 8:36
  • However, before implementing the atan2 function yourself, I would request you to check the API of TinyOS to see whether atan2 is supported. Generally this function is found in the math library of programming languages.
    – DotPi
    Apr 19, 2013 at 8:39
  • o, i will check that. if i want to follow this equation <b> =ACOS(SIN(lat1)*SIN(lat2)+COS(lat1)*COS(lat2)*COS(lon2-lon1))*6371 </b> then the (lat,lon) in radian, but also when i use cos or cosd cos for degree cosd for radian i am confused if i use long and lat in radian then use the (cos and sin) in radian or degree ?
    – H.H
    Apr 19, 2013 at 8:45
  • Generally one should use radians for calculations related to angles. You can use the normal cos and sin functions as long as you are using radians.
    – DotPi
    Apr 19, 2013 at 8:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.