Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

First, sorry if this questions sound very simple. I am very new to GIS.

Given four values of north/south latitude, east/west longitude how to calculate the center point that is correct for all cases on earth?

                  ----------(north latitude)---------------
                 |                                         |
                 |                                         |
 (west longitude)|                ? (calculate this point) |(east longitude)
                 |                                         |
                 |                                         |
                  ----------(south latitude) --------------

The dateline is an issue if you just use the following formula (N+S)/2 and (E+W)/2 to calculate the center.

share|improve this question

I think you could use the Midpoint formula found at Moveable Type Scripts.

This is the half-way point along a great circle path between the two points.1 Formula:

Bx = cos(φ2).cos(Δλ)
By = cos(φ2).sin(Δλ)
φm = atan2( sin(φ1) + sin(φ2), √((cos(φ1)+Bx)² + By²) )
λm = λ1 + atan2(By, cos(φ1)+Bx)


var Bx = Math.cos(lat2) * Math.cos(dLon);
var By = Math.cos(lat2) * Math.sin(dLon);
var lat3 = Math.atan2(Math.sin(lat1)+Math.sin(lat2),
                      Math.sqrt( (Math.cos(lat1)+Bx)*(Math.cos(lat1)+Bx) + By*By ) ); 
var lon3 = lon1 + Math.atan2(By, Math.cos(lat1) + Bx);
share|improve this answer
+1. Some important details and cautions: (1) "Δλ" is the difference of longitudes, lambda2 - lambda1 (and phi1 and phi2 are latitudes); (2) atan2(y,x) computes an angle whose tangent is y/x (not x/y, as is found in some implementations); (3) in some cases λm must be reduced modulo 360 degrees to lie between -180 and 180 degrees; (4) the formula is correct for the sphere; for an ellipsoid the relative error is good, but the absolute error can be considerable: see… for an analysis. – whuber Mar 22 '13 at 15:16

The previous answer recommends using a script from the Movable Type site, but when checking that site more carefully we find that they now provide another solution that is simpler, and that also works near (and at) the Poles and the dateline:

Their new solution is based on n-vectors (, and calculating a midpoint with n-vectors is very simple, as demonstrated in example 7 at

The original question asked for a solution that is "correct for all cases on earth", and then the vector-based solution should be used instead of the solution based on lat/long.

In addition: Since the n-vectors are normal to the earth ellipsoid, the n-vector solution will also work for the case of ellipsoidal earth model.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.