Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I'm using a query I found on stackoverflow for finding locations near a given latitude/longitude in a database. Below is the query. Entirely out of curiosity, can someone explain what exactly it's doing (the math bits, not the sql)? 44.xxx and -93.xxx is the lat/long to start from.

Thanks!

SELECT id, ( 3959 * 
acos( cos( radians(44.96577) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(-93.268433) ) + sin( radians(44.907411) ) * sin( radians( latitude ) ) ) ) 
AS distance 
FROM ivr_sign.property 
HAVING distance < 10 
ORDER BY distance ASC, id ASC LIMIT 10
share|improve this question

1 Answer 1

This formula uses the Spherical law of cosines to calculate the great circle distance between two points, given their latitudes and logitudes.

In particular, it calculates the distance between fixed point (lat $44.\cdots$, long $-93.\cdots$) with the known points in the database.

The 3959 is (an approximation of) the radius of the earth in miles.

share|improve this answer

Your Answer

 
discard

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.