mysql 计算地图上两点之间的距离

阅读更多

     数据库表:

     

CREATE TABLE `tb_location` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `longitude` double DEFAULT NULL,
  `latitude` double DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8

 

   sql语句:

   赤道半径:6378.137km

   参考经度:120.120383,纬度:30.292069

SELECT t.id,(6378.137 * 2 * ASIN(SQRT(POW(SIN((RADIANS(30.292069)-RADIANS(t.latitude))/2),2) + COS(RADIANS(30.292069))*COS(RADIANS(t.latitude))*POW(SIN((RADIANS(120.120383)-RADIANS(t.longitude))/2),2))) 
) AS distance FROM tb_location t

  查询结果为km,可自行处理。

你可能感兴趣的:(mysql,LBS)