This is an old revision of the document!


Geographic Searches - Radius Distance Searches

The Math Behind Radius Distance Searches

The math behind radius searches is somewhat complex, and there are several possible approaches.

Why not use ranges of latitude and longitude?

One might think that the easiest approach would be to simply search for a latitude between x and y, and a longitude between x and y. This is very simple, but leads to a lot of inaccuracy. Such a range produces something close to a square rather than a circle. (In fact, because of the nature of longitudinal lines, it produces a near-trapezoid shape.) The area of a circle is about 78% of the area of a radius, so this would lead to a lot of additional rows that are not intended. Moreover, the corner of the square is about 141% of the radius of the circle, and that would be generally unacceptable.

Remember the Pythagorean algorithm?

Remember “a2 + b2 = c2”? This Pythagorean algorithm calculates the third side of a right triangle, called a hypotenuse. If the Earth was completely flat, and map coordinates were completely squares, this would be an easy way to calculate distances. But alas, the Earth is a sphere, or an egg-shaped, slightly wobbly approximation of a sphere, so Euclidean geometry will not give us the desired result.

 
Back to top
admin/optimization/geo/math.1280290955.txt.gz · Last modified: 2012/10/26 14:52 (external edit)