views:

1306

answers:

3

Say you have n GPS coordinates how could you work out the central gps point between them?

+4  A: 

Depends on what you mean by the central GPS point. You could simply take the average of all the points, as suggested by Stephen - but keep in mind that GPS coordinates are not continuous - this will fail spectacularly around discontinuities such as the poles.

In most cases you'll need to convert to a coordinate system that doesn't have this issue.

You could also look at all the points bounded by it, calculated all the distances to each GPS point, and minimize the sum of the distances to all the GPS points. You'll need to look into great circle calculations for this.

Further, each GPS might have a higher or lower degree of uncertainty, you should take that into account and weight them accordingly.

What exactly are you trying to find out?

Adam Davis
+1  A: 

This is a 3 dimensional problem. If the points are close enough together, you might be able to pretend it isn't and the error introduced might not be too bad. If you want to do it right, this is one of the magic formulas. Here is some good background material. As to off she shelf software packages for this problem space, I've only heard of Hipparchus, but I'm sure there are many others.

Mark Johnson
+5  A: 

In case it helps anyone now or in the future, here's an algorithm that's valid even for points near the poles (if it's valid at all, i.e. if I haven't made a silly math mistake ;-):

  1. Convert the latitude/longitude coordinates to 3D Cartesian coordinates:

    x = cos(lat) * cos(lon)
    y = cos(lat) * sin(lon)
    z = sin(lat)
    
  2. Compute the average of x, the average of y, and the average of z:

    x_avg = sum(x) / count(x)
    y_avg = sum(y) / count(y)
    z_avg = sum(z) / count(z)
    
  3. Convert that direction back to latitude and longitude:

    lat_avg = arctan(z_avg / sqrt(x_avg ** 2 + y_avg ** 2))
    lon_avg = arctan(y_avg / x_avg)
    
David Zaslavsky
Division by zero!
Gareth Rees
arctan(x/0) = pi/2 * sign(x)
David Zaslavsky
But I guess you do raise a point, an actual implementation would probably use an arctan2(num, denom) function.
David Zaslavsky
I just tried implementing this and longitude is fine but latitude is way out. Keep going back over my code and it seems ok, am I tired or is there a mistake in the algorithm?
Adam Taylor
I just rechecked it (implemented in Mathematica) and it seems to work fine for me... make sure that pi/2 radians (or +90 degrees) latitude is the north pole, 0 is the equation, and -pi/2 (or -90) is the south pole.
David Zaslavsky
I'm not sure what you mean. Here's the code I implemented http://pastebin.com/m4ff87c5a The longitude is coming out fine but not the latitude?
Adam Taylor
Also I didn't understand your second comment so I ignored it. I guess that was maybe a bad move?
Adam Taylor
About the arctan2 function? That only makes a difference when x_avg is 0, so I doubt that's your problem. Or if you're talking about the degrees/radians thing: you'll have to multiply by 180/Math.PI if you're working with degrees. If that doesn't help, maybe you should start a new question about it.
David Zaslavsky
P.S. If you do start a new question, I'd suggest expanding that pastebin snippet into a full Java class that at least compiles.
David Zaslavsky