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;
PHP is one of the most widely used open-source server-side scripting languages that exist today. With over…
in:Scripts and tutorials (0 comments)In a FBML Facebook App, your quick jump menu will require a little tweak to work in FBJS…
in:Scripts and tutorials (0 comments)Every single day, someone, somewhere is discussing something important to your business; your brand, your executives, your…
in:Scripts and tutorials (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)Because of the near-spherical shape of the Earth, calculating an accurate distance between two points requires the use…
in:Scripts and tutorials (1 comments)With this script we can limit the download speed // local file that should be send to the client $local_file…
in:Scripts and tutorials (0 comments)Some hosts disabled the ini setting allow_url_fopen. This also means that the ability to easily grab images…
in:Scripts and tutorials (0 comments)The act to verify if a file exists, is one of more important tasks related to files operations,…
in:Scripts and tutorials (0 comments)
