# Calculate average latitude / longitude

I have the array of geographical coordinates (latitude & longitude).

What is the best way to calculate average latitude and longitude?

Thanks!

-
Any reason why the arithmetic mean will not do? (Take north latitude as positive and south latitude as negative; take east longitude as positive and west longitude as negative, if that's an issue) – Arturo Magidin Jun 26 '11 at 22:05
@Arturo: There might be a problem if for example all of the points are in the Pacific but the average longitude is in Africa. – Henry Jun 26 '11 at 22:09

The conventional method is to convert latitudes ($\phi_i$) and longitudes ($\lambda_i$) into three dimensional points $(x_i,y_i,z_i)$ using
$$(R \cos \phi_i \cos \lambda_i, R \sin \phi_i \cos \lambda_i , R \sin \lambda_i )$$
then take the mean of these points $(\bar{x},\bar{y},\bar{z})$, generally giving you a point inside the sphere, and then converting this direction back to latitude and longitude, using something like $$\bar{\phi} = \text{atan2}\left(\bar{y},\bar{x}\right) \text{ and } \bar{\lambda} = \text{atan2}\left(\bar{z},\sqrt{\bar{x}^2+\bar{y}^2}\right).$$
Proportionately how far the mean point is inside the sphere, i.e. $\frac{\sqrt{\bar{x}^2+\bar{y}^2+\bar{z}^2}}{R}$, is an indicator of dispersion of the original points.