Last active
June 1, 2017 22:40
-
-
Save clintonhalpin/fd18f4e93cac9e3523ba799bb48d06e7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
DROP TABLE locations_test; | |
CREATE TABLE locations_test ( | |
id int(11) unsigned NOT NULL AUTO_INCREMENT, | |
name text, | |
latitude decimal(10,7) DEFAULT NULL, | |
longitude decimal(10,7) DEFAULT NULL, | |
PRIMARY KEY (id) | |
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8; | |
INSERT INTO locations_test (`id`, `name`, `latitude`, `longitude`) | |
VALUES | |
(1, 'San Fransisco', 37.7739720, -122.4312970), | |
(2, 'New York', 40.7127837, -74.0059413), | |
(3, 'Philadelphia', 39.9525839, -75.1652215); | |
/* | |
Brooklyn: 40.6782,-73.9441579 | |
Oakland: 37.8044,-122.2711 | |
Camden: 39.9259463,-75.1196199 | |
*/ | |
select | |
name, | |
FLOOR(3959 * acos( | |
cos(radians(40.6782)) * cos(radians( latitude )) * cos(radians( longitude ) - radians(-73.9441579)) + sin( radians(40.6782)) * sin(radians( latitude )) | |
)) as miles | |
from locations_test | |
order by miles |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment