0

My goal is to use GPS to measure the distance that I moved with my phone. My problem is, that the results are imprecise. I've used the following code to calculate the distance:

public double getDistance(GeoCoordinate p1, GeoCoordinate p2)
{
    double d = p1.Latitude * 0.017453292519943295;
    double num3 = p1.Longitude * 0.017453292519943295;
    double num4 = p2.Latitude * 0.017453292519943295;
    double num5 = p2.Longitude * 0.017453292519943295;
    double num6 = num5 - num3;
    double num7 = num4 - d;
    double num8 = Math.Pow(Math.Sin(num7 / 2.0), 2.0) + ((Math.Cos(d) * Math.Cos(num4)) * Math.Pow(Math.Sin(num6 / 2.0), 2.0));
    double num9 = 2.0 * Math.Atan2(Math.Sqrt(num8), Math.Sqrt(1.0 - num8));
    return (6376500.0 * num9);
}

This is my OnLocationChanged implementation:

bool begin = true;

public void OnLocationChanged(Location location)
{

    _aktuellerOrt = location;
    //aktuellerOrt.Speed is always 0, so I cannot use that.
    if (_aktuellerOrt == null)
    {
        //message
    }
    else
    {

        if (_aktuellerOrt.Accuracy > 70) //I found values around 130 to be more or less good
        {
            _locationText.Text = String.Format("{0}, {1}", _aktuellerOrt.Latitude, _aktuellerOrt.Longitude);
            GeoJetzt = new GeoCoordinate();
            GeoJetzt.Latitude = _aktuellerOrt.Latitude;
            GeoJetzt.Longitude = _aktuellerOrt.Longitude;
            if (beginn)
            {
                GeoVorher = new GeoCoordinate();
                GeoVorher.Latitude = _aktuellerOrt.Latitude;
                GeoVorher.Longitude = _aktuellerOrt.Longitude;
                beginn = false;
            }
            else
            {
                double abstand = getDistance(GeoVorher, GeoJetzt);
                weg += abstand;
                if (weg >= 1)
                    _distanzText.Text = weg + " kilometers";
                else
                    _distanzText.Text = (weg * 1000) + " meters";
                _distanzText.Text += " (" + abstand + ", " + _aktuellerOrt.Accuracy + ")";
                GeoVorher = new GeoCoordinate();
                GeoVorher.Latitude = _aktuellerOrt.Latitude;
                GeoVorher.Longitude = _aktuellerOrt.Longitude;
            }
        }
        else
            _locationText.Text = "Too coarse, now " + _aktuellerOrt.Accuracy + ".";
    }
}

The problem is, I get values for abstand within the kilometer range while not moving the phone.

What are best practices for imprecise signals? My goal is to measure the distance while jogging or running, so 10 - 16 km/h.

  • Walking isn't 10 km/h, it is more like 5 km/h (http://en.wikipedia.org/wiki/Walking_speed), anyways, you would use a low pass filter for that. You can try this Kalman filter: http://stackoverflow.com/a/15657798/368379 and see if that works better. – Cheesebaron Jul 21 '14 at 11:37
  • @Cheesebaron Which value do you recommend for Q_metres_per_second? – Timo Theobald Jul 21 '14 at 16:46
  • Did you even read the text the guy provided? He made a lot of effort into creating that answer and even gives you an answer to what Q value to use. – Cheesebaron Jul 22 '14 at 09:08

0 Answers0