GPS formulas

I am trying to write up a code using the known GPS position to caluate the distance to a given point>

 

long  distance  =  dist2Point(long latitudeOfPoint,long longitudeOfPoint)

 

and also distance to a given line which goes between to GPS points>

 

long  distance2Line  =  dist2Point(long latitudeOfPointStart,long longitudeOfPointStart, long latitudeOfPointEnd,long longitudeOfPointEnd)

 

 

any ideas how to do this by using snippets of existing code?

 

Thanks for all ideas

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

  • I find this site full of useful info.
    Calculate distance and bearing between two Latitude/Longitude points using haversine formula in Jav…
  • Developer

    long get_distance(struct Location *loc1, struct Location *loc2)
    {
     if(loc1->lat == 0 || loc1->lng == 0)
      return -1;
     if(loc2->lat == 0 || loc2->lng == 0)
      return -1;
     float dlat   = (float)(loc2->lat - loc1->lat);
     float dlong  = ((float)(loc2->lng - loc1->lng)) * scaleLongDown;
     return sqrt(sq(dlat) + sq(dlong)) * .01113195;
    }

     

    taken from navigation.pde

This reply was deleted.

Activity