browser lang:en
Suppose that we want to find the five nearest places to (47.470779, -87.890699) using Spherical Law of Cosines, the following MySQL syntax would easily accomplish it:
SELECT * AS place,
(DEGREES(
ACOS(
SIN(RADIANS(47.470779)) * SIN(RADIANS(geo_latitude)) +
COS(RADIANS(47.470779)) * COS(RADIANS(geo_latitude)) *
COS(RADIANS(-87.890699 - geo_longitude))
)
) * 60 * 1.1515)
AS distance FROM `MyDatabase`.`allplaces` ORDER BY distance ASC LIMIT 20 ;
Suppose that we want to find the five nearest places to (47.470779, -87.890699) using Haversine Formula, the following MySQL syntax would easily accomplish it [please refer here to read about the motivation/reasoning behind using atan2() function instead of sin(min()).
SELECT * ,
((2 * 3960 *
ATAN2(
SQRT(
POWER(SIN((RADIANS(47.470779 - geo_latitude))/2), 2) +
COS(RADIANS(geo_latitude)) *
COS(RADIANS(47.470779 )) *
POWER(SIN((RADIANS(-87.890699 - geo_longitude))/2), 2)
),
SQRT(1-(
POWER(SIN((RADIANS(47.470779 - geo_latitude))/2), 2) +
COS(RADIANS(geo_latitude)) *
COS(RADIANS(47.470779 )) *
POWER(SIN((RADIANS(-87.890699 - geo_longitude))/2), 2)
))
)
)) AS distance FROM `MyDatabase`.`allPlaces` ORDER BY distance LIMIT 20;
Have you ever had to develop something yourself only to find out that there had already been…
in:JQuery (0 comments)The situation begins with your blog or website and you need to post some code on a particular…
in:The Holy Faq's (0 comments)So. Google just recently announced Google Buzz. I’m not sure about you, but I…
in:Blog (0 comments)There's lots of clever scripts around to tell you how to get images in and out of…
in:PHP scripts (0 comments)Spherical Law of Cosines Suppose that we want to find the five nearest places to (47.470779, -87.890699) using Spherical…
in:MySql (0 comments)I have always used Dreamweaver, and love it. But, I have been thinking, what are the FREE CSS…
in:Free Software (0 comments)Advanced Linux Sound Architecture (known by the acronym ALSA) is a Linux kernel component intended to replace the…
in:Blog (0 comments)The Singleton Pattern is one of the GoF (Gang of Four) Patterns. This particular pattern provides a…
in:Scripts and tutorials (0 comments)
