forked from mthornhill/geonames
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jordan
committed
Jul 11, 2010
1 parent
f03b8d4
commit 9812f08
Showing
1 changed file
with
21 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
DROP FUNCTION IF EXISTS fn_distance_cosine_km; | ||
DELIMITER | | ||
CREATE FUNCTION fn_distance_cosine ( | ||
point1 POINT, | ||
point2 POINT | ||
) | ||
RETURNS DOUBLE | ||
BEGIN | ||
DECLARE latitude_1, longitude_1, latitude_2, longitude_2 DOUBLE; | ||
SET latitude_1:=X(point1); | ||
SET longitude_1:=Y(point1); | ||
SET latitude_2:=X(point2); | ||
SET longitude_2:=Y(point2); | ||
RETURN ACOS( | ||
SIN(RADIANS(latitude_1)) * SIN(RADIANS(latitude_2)) | ||
+ COS(RADIANS(latitude_1)) * COS(RADIANS(latitude_2)) | ||
* COS(RADIANS(longitude_2 - longitude_1)) | ||
) * 6371; | ||
END | ||
| | ||
DELIMITER ; |