Q:

Calculate Current Speed in .NET - With GPS

I would like to know what's the best way to calculate the current speed with GPS.
I've an external GPS receiver which is connected via USB to my car-notebook. It gives me just the following information:
- Longitude
- Latitude
- Altitude
My try is to get two location-infos with timestamps.
Then I am finding the difference in time (timestamp2 - timestamp1) and calculating the speed (distance/time).
Are there any other possibilites oder maybe any libraries available?

A:

To calculate the distance, you will need the Haversine Formula.
You will find many implementations of it around the web, here is one I use in C#:
private static double ArcInMeters(double lat0, double lon0, double lat1, double lon1)
{
    double earthRadius = 6372797.560856; // m
    return earthRadius * ArcInRadians(lat0, lon0, lat1, lon1);
}

private static double ArcInRadians(double lat0, double lon0, double lat1, double lon1)
{
    double latitudeArc = DegToRad(lat0 - lat1);
    double longitudeArc = DegToRad(lon0 - lon1);
    double latitudeH = Math.Sin(latitudeArc * 0.5);
    latitudeH *= latitudeH;
    double lontitudeH = Math.Sin(longitudeArc * 0.5);
    lontitudeH *= lontitudeH;
    double tmp = Math.Cos(DegToRad(lat0)) * Math.Cos(DegToRad(lat1));
    return 2.0 * Math.Asin(Math.Sqrt(latitudeH + tmp * lontitudeH));
}

private static double DegToRad(double x)
{
    return x * Math.PI / 180;
}

