Sign up ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Possible Duplicate:
What is the right solution (and map projection) to compute distances between points located all over the World?

I want to know how I could calculate the center-to-center distance between two (or even more) circles, based on their center's Geo-coordinates values?

I'm new in this area, gonna use this one for Goolge Maps API 3 via Javascript and PHP. Probably the algorithm should be enough, however more details are appreciated. :)


The circles are not necessary to mention as part of the problem, as it could apply to two points, instead of two circles' centers. Actually I'm trying to do some overlap detection stuff on a crisis mapping application.

The locations are relatively close to each other, however I prefer to go for a fail-safe solution which could apply on most of the cases (if not all).

Also it doesn't need an accurate result, as all the visualizations on this web application are somehow approximate by default, so there is no great rush for having a perfect-accurate solution for now, but same as above, I personally prefer to go for the best choice, if it's not gonna add so much difficulties on the solution.

share|improve this question

marked as duplicate by whuber Oct 19 '12 at 16:41

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

How general does this need to be? For instance, could the circles be located anywhere on the earth or are they guaranteed to be close? How accurate must the answers be? Why do you mention circles when the question seems to be only about the centers--are some special conditions or criteria perhaps unstated? – whuber Oct 19 '12 at 14:21
@whuber Thanks for the comment! I have updated the original post with answers. :) – Mahdi Oct 19 '12 at 16:02

1 Answer 1

up vote 1 down vote accepted

There's a fantastic explanation of the various algorithms for calculating distances between points given latitude and longitude located here.

The gist of it is this:

For intuitive simplicity, you could start with the Equirectangular approximation, which is derived from the pythagorean theorem. However, this is a bad choice as it grows in imprecision as you move away from the equator (the Mercator projection deficiency).

If you're not at all concerned about wrapping your head around the problem, just use the spherical law of cosines:

var d = Math.acos(Math.sin(lat1)*Math.sin(lat2) + 
              Math.cos(lat1)*Math.cos(lat2) *
              Math.cos(lon2-lon1)) * R;

where R is an approximation of the radius of the earth in the desired units.

share|improve this answer
thanks, that's really gonna help! :) ... let see what others gonna offer also ... I'm wondering if there would be other solutions also :) – Mahdi Oct 19 '12 at 16:17
Also, check out this discussion on the topic:… – AABoyles Oct 19 '12 at 16:20
thanks! that looks a little bit complicated for me, but interesting! I'm very new on GIS! – Mahdi Oct 19 '12 at 16:30
Just to be clear: these are all calculations for a spherical earth model, not for an ellipsoidal datum. Also, the reason for the Haversine solution is that the Law of Cosines calculations become numerically unstable at short distances--which looks like it's the intended application. See – whuber Oct 19 '12 at 16:39

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