Measuring Distance by Lat & long in Arduino

Hi everyone
I have a project that I need to measuring distance by 2 different gps locations

Assume that there are tow Lats and two Longs like this:
float Lat1=30.240455
float Long1=-97.817710
float Lat2=30.236640
float Long2=-97.821456

how can i measure distance between them in Arduino?

You would want to use the spherical law of cosines, like this:

=ACOS( SIN(lat1)*SIN(lat2) + COS(lat1)*COS(lat2)*COS(lon2-lon1) ) * 6371000

6371000 is the radius of the earth in meters.

This is also known as the Haversine formula, which is already implemented in Arduino:

https://hutscape.com/tutorials/haversine

How would you calculate the distance between them without using and Arduino ?

Can "Mr. Google" help, I wonder ?

Thanks for your favor it solved my issue

Use the TinyGPSplus library, that provides very easy to use functions for calculating distance and direction between two sets of co-ordinates, for instance;

distance = TinyGPSPlus::distanceBetween(Lat1, Lon1, Lat2, Lon2);

The caclulation from TinyGPSplus is accurate to within a metre or so on the checks I have done. I did run a real World test using standard GPS reference points (positions know to sub cm level) to see if the library calculations were good enough.

There are other mathematical methods but I have not checked their real world accuracy, maybe others have.

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