1

In the Iphone SDK the distanceFromLocation: says it doesn't use altitude at all. If I'm writing an app to track how far I walk/cycle/ect (yes I know there are a number that do this already), I'm curious how much that matters. Does anyone have experience with this?

When I say cartesian cords I mean something like this (in C#, not objective C):

        double lattitude, longitude, altitude, x, y, z, x1, y1, z1, S;
        double a = 6378137, C, f = 1 / 298.257224;

        lattitude = <insert degrees> * Math.PI / 180.0;
        longitude = <insert degrees> * Math.PI / 180.0;
        altitiude = <insert altitude>

        C= 1 / (Math.Sqrt(Math.Pow(Math.Cos(lattitude),2.0) + Math.Pow((1 - f),2.0) *Math.Pow(Math.Sin(lattitude),2.0)));
        S = Math.Pow(1 - f, 2.0) * C;
        x = (a*C+altitude) * Math.Cos(lattitude) * Math.Cos(longitude);
        y = (a*C+altitude) *Math.Cos(lattitude) * Math.Sin(longitude);
        z = (a*S+altitude) * Math.Sin(lattitude);

        lattitude = <insert degrees new> * Math.PI / 180.0;
        longitude = <insert degrees new> * Math.PI / 180.0;
        altitiude = <insert altitude new>;


        x1 = (a * C + altitude) * Math.Cos(lattitude) * Math.Cos(longitude);
        y1 = (a * C + altitude) * Math.Cos(lattitude) * Math.Sin(longitude);
        z1 = (a * S + altitude) * Math.Sin(lattitude);

        double distance;
        distance = Math.Sqrt(Math.Pow(x1 - x, 2.0) + Math.Pow(y1 - y, 2.0) + Math.Pow(z1 - z, 2.0));

Does anyone know how much of a difference it actually makes? Essentially how it is calculated precisely on iphone? Great circle distance? I can't seem to find the answer anywhere

Justin Boo
  • 10,132
  • 8
  • 50
  • 71
zlittle
  • 11
  • 1

1 Answers1

1

The docs say:

"This method measures the distance between the two locations by tracing a line between them that follows the curvature of the Earth. The resulting arc is a smooth curve and does not take into account specific altitude changes between the two locations."

To me, that implies Great Circle distance (in fact, it's nearly the definition of it).

My understanding (though I'm certainly no expert) is that great circle calculations (such as Haversine) are very typical, and generally considered "good enough" for most applications.

There's probably way more information than you want on the topic here. This question is semi-related as well.

If you're really concerned about it, I'd try a few different algorithms, and see if you can determine which best suits your needs.

Community
  • 1
  • 1
zpasternack
  • 17,838
  • 2
  • 63
  • 81