Here's my snippet of code that does both distance and heading (although I
think in terms of bearings, not headings):
track = gpsdata->fix.track;
speed = gpsdata->fix.speed;
...
if (speed < 0.3 ) sprintf(brg, "");
else if (track < 1.0)
sprintf (brg, "N");
else if (track < 89.0)
sprintf (brg, "N%.0fE", track);
else if (track < 91.0)
sprintf (brg, "E");
else if (track < 179.0)
sprintf (brg, "S%.0fE", 180.0 - track);
else if (track < 181.0)
sprintf (brg, "S");
else if (track < 269.0)
sprintf (brg, "S%.0fW", track - 180.0);
else if (track < 271.0)
sprintf (brg, "W");
else if (track < 359.0)
sprintf (brg, "N%.0fW", 360 - track);
else
sprintf (brg, "N");
if(speed < 0.5) sprintf (info, "stopped");
else sprintf (info, "\"%s %.0f MPH\"", brg, speed * 2.237);
If you keep track of the last lat & long you can also get the distance:
double
haversine_mi (double lat1, double long1, double lat2, double long2)
{
double d2r = 0.0174532925;
double dlong = (long2 - long1) * d2r;
double dlat = (lat2 - lat1) * d2r;
double a = pow (sin (dlat / 2.0), 2) +
cos (lat1 * d2r) * cos (lat2 * d2r) * pow (sin (dlong / 2.0), 2);
double c = 2 * atan2 (sqrt (a), sqrt (1 - a));
double d = 3956 * c;
return d;
}
(Sorry it's C code but it should all translate to python).
On Thu, November 3, 2011 1:06 pm, Charles Curley wrote:
> On Thu, 3 Nov 2011 19:37:06 +0000
> Neil Greenough <
neilgreenough@...> wrote:
>
>> I'm currently writing a script in Python which records the longitude,
>> latitude and speed from the GPS device. What I'd like to do is also
>> record the direction of travel / bearing for each hit (ie. North,
>> South, East, West). I've tried researching this but to no avail. Any
>> suggestions on how this can be implemented or does anyone have any
>> examples of Python code containing bearings?
>
> Direction of travel, or heading, and bearing are not the same thing.
> Heading is the direction in which you are moving, i.e. your course
> made good. Bearing is the angle from the heading to a feature.
>
> That nitpick aside... In C:
>
> if (gpsdata.set & TRACK_SET) {
> formatTrack (gpsdata.fix.track);
> }
>
> gpsdata.fix.track is a double, and seems to be a value in the range 0 to
> 360, of degrees from true north, where 0 and 360 are both true north.
> (To be really pedantic, it should be either 0-359 or 1-360, but I
> actually prefer the extra degree.)
>
>
>
> --
>
> Charles Curley /"\ ASCII Ribbon Campaign
> Looking for fine software \ / Respect for open standards
> and/or writing? X No HTML/RTF in email
>
http://www.charlescurley.com / \ No M$ Word docs in email
>
> Key fingerprint = CE5C 6645 A45A 64E4 94C0 809C FFF6 4C48 4ECD DFDB
> _______________________________________________
> Gpsd-users mailing list
>
Gpsd-users@...
>
https://lists.berlios.de/mailman/listinfo/gpsd-users>
> !DSPAM:4eb2f44e263845133180498!
>
>
--
Pain is temporary. It may last a minute, or an hour, or a day, or a year,
but eventually it will subside and something else will take its place. If
I quit, however, it lasts forever.
_______________________________________________
Gpsd-users mailing list
Gpsd-users@...
https://lists.berlios.de/mailman/listinfo/gpsd-users