I am trying to calculate and return the distances between some points.
Here is the complete MYSQL statement that I am using. I have tried multiple versions of this formula, and they all have similar results: returning zero result. Any thoughts on what I am doing wrong?
SET @origLat = 37.386337;
SET @origLon = -122.085823;
SET @dist = 20;
SELECT user_id, user_lat, user_lon, 3956 * 2 *
ASIN(SQRT( POWER(SIN((@origLat - abs(user_lat))*pi()/180/2),2)
+COS(@origLat*pi()/180 )*COS(abs(user_lat)*pi()/180)
*POWER(SIN((@origLon-(user_lon))*pi()/180/2),2)))
AS distance
FROM myTable
WHERE user_lon BETWEEN (@origLon-@dist/abs(cos(radians(@origLat))*69)) AND (@origLon+@dist/abs(cos(radians(@origLat))*69)) AND
user_lat BETWEEN (@origLat-(@dist/69)) AND (@origLat+(@dist/69))
HAVING distance < @dist ORDER BY distance LIMIT 100
Here is what is in my table.
Running just my SELECT clause shows that Distance is return nil.