# Project by Matthew18771; Vehicle GPS Logger and Speedometer

I have just shared a new project: “Vehicle GPS Logger and Speedometer”

PurposeTo display time and speed to a driver while logging timestamped raw latitude, longitude and speed as returned by the GPS satellite network. This allows a driver to double-check their speedometer reading and provides an audit trail that can be…

4 Likes

Great project write up.

Here is some C code for the haversine formula

``````#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define R 6371
double dist(double th1, double ph1, double th2, double ph2)
{
double dx, dy, dz;
ph1 -= ph2;

dz = sin(th1) - sin(th2);
dx = cos(ph1) * cos(th1) - cos(th2);
dy = sin(ph1) * cos(th1);
return asin(sqrt(dx * dx + dy * dy + dz * dz) / 2) * 2 * R;
}

/**
* nn.nn North must be +ve
* nn.nn South must be -ve
* nn.nn East must be +ve
* nn.nn West must be -ve
*
* th1, ph1 first NS EW coordinate in decimal degrees
* th2, ph2 second NS EW cordinate in decimal degrees.
*/

/*
* Calc distance between 36.12 N, 86.67 W and 33.94 N, 118.4 W
*/

int main()
{
double d = dist(36.12, -86.67, 33.94, -118.4);
/* Americans don't know kilometers */
printf("dist: %.1f km (%.1f mi.)\n", d, d / 1.609344);

return 0;
}

// compiling with math lib linked
mjt@daemon2:~ %  cc haversine.c -lm -o haversine

// running the program
mjt@daemon2:~ %  ./haversine
dist: 2886.4 km (1793.6 mi)

``````

code found here

You might be able to add a pair of triggers to setup starting and ending locations to calculate the distance ‘as the crow flies’

Murray

3 Likes

Awesome project Matthew! As someone who has admittedly been in a similar sort of trouble in the past, maybe I should mount one on my car

Cheers for the extra code @Murray125532, your C expertise never goes astray!

1 Like

Hi James & Matthew,

I incorporated similar haversine code into a project at work many moons ago, when we needed to determine point to point distances between service centres and Pick Up Drop Off locations (PUDOs) across Australia. This was used then to set \$\$ charge rates…
The Powers That Be though that was a simpler (better?) value than road travel distances, since they could be determined by GPS locations.

Murray

1 Like

Hi Matthew,
Great project, trying to create this for me too. But some errors:
Some things seem to be missing.
The includes are empty and verifying gives errors.
Can you help, or drop the full code?
Thanks,
Ton

Hi Ton,

Sorry about that! It was actually a formatting issue with the article itself, you can find the working guide here:

(The normal link will work tomorrow)

Liam

3 Likes