· 7 years ago · Sep 13, 2018, 11:04 AM
1Select nearest longitude/latitude values from DB
2CREATE TABLE IF NOT EXISTS `buss_StopPoints` (
3 `Name` varchar(50) NOT NULL,
4 `LocationNorthing` varchar(30) NOT NULL,
5 `LocationEasting` varchar(30) NOT NULL
6) ENGINE=InnoDB DEFAULT CHARSET=latin1;
7
8INSERT INTO `buss_StopPoints` (`Name`, `LocationNorthing`, `LocationEasting`) VALUES ('Some station', '59.3195952318672', '18.0717401337168');
9INSERT INTO `buss_StopPoints` (`Name`, `LocationNorthing`, `LocationEasting`) VALUES ('Some station 2', '59.3195772927918', '18.0717389396547');
10INSERT INTO `buss_StopPoints` (`Name`, `LocationNorthing`, `LocationEasting`) VALUES ('Some station 3', '59.3234014331742', '18.0671617033088');
11INSERT INTO `buss_StopPoints` (`Name`, `LocationNorthing`, `LocationEasting`) VALUES ('Some station 4', '59.3233921590479', '18.0671786573678');
12INSERT INTO `buss_StopPoints` (`Name`, `LocationNorthing`, `LocationEasting`) VALUES ('Some station 5', '59.3313179695727', '18.061677395945');
13
14LAT = latitude value
15LON = longitude value
16
17SELECT Name, (6371 * acos( cos( radians(LAT) ) * cos( radians( LocationNorthing ) ) * cos( radians( LON ) - radians(LocationEasting) ) + sin( radians(LAT) ) * sin( radians(LocationNorthing) ) )) AS distance order by distance