zoukankan      html  css  js  c++  java
  • mysql使用sql语句根据经纬度计算距离排序

    CREATE TABLE `locationpoint` (
      `id` int(11) NOT NULL,
      `province` varchar(20) NOT NULL,
      `city` varchar(20) NOT NULL,
      `longitude` double(10,3) NOT NULL,
      `latitude` double(10,3) NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8
    
    INSERT INTO `locationPoint` VALUES ('1147','安徽省', '合肥', '117.170', '31.520');
    INSERT INTO `locationPoint` VALUES ('1148','安徽省', '安庆', '117.020', '30.310');
    INSERT INTO `locationPoint` VALUES ('1149','安徽省', '蚌埠', '117.210', '32.560');
    INSERT INTO `locationPoint` VALUES ('1150','安徽省', '亳州', '115.470', '33.520');
    INSERT INTO `locationPoint` VALUES ('1151','安徽省', '巢湖', '117.520', '31.360');
    INSERT INTO `locationPoint` VALUES ('1152','安徽省', '滁州', '118.180', '32.180');
    INSERT INTO `locationPoint` VALUES ('1153','安徽省', '阜阳', '115.480', '32.540');
    INSERT INTO `locationPoint` VALUES ('1154','安徽省', '贵池', '117.280', '30.390');
    INSERT INTO `locationPoint` VALUES ('1155','安徽省', '淮北', '116.470', '33.570');
    

      

    SELECT  
        city,  
        longitude,  
        latitude,  
        ROUND(  
            6371.393 * 2 * ASIN(  
                SQRT(  
                    POW(  
                        SIN(  
                            (  
                                22.53462 * 3.1415926 / 180 - latitude * PI() / 180  
                            ) / 2  
                        ),  
                        2  
                    ) + COS(22.53462 * 3.1415926 / 180) * COS(latitude * PI() / 180) * POW(  
                        SIN(  
                            (  
                                113.9602 * 3.1415926 / 180 - longitude * PI() / 180  
                            ) / 2  
                        ),  
                        2  
                    )  
                )  
            ) * 1000  
        ) AS distance_um  
    FROM  
        locationpoint  
    ORDER BY  
        distance_um ASC  
  • 相关阅读:
    数据清洗
    JAVA多线程三种实现方式
    QT-4.8.6 编译配置过程
    qt 编译问题总结
    [转载]tslib1.4与Qt4.8.6的交叉编译与移植
    STC12C5A60S2 @ 22.0184Mhz 精确延时
    STC12C5A60S2 双串口通信
    C# Bitmap 复制
    TextMate2 最新版下载及源码编译过程
    mac系统 PHP Nginx环境变量修改
  • 原文地址:https://www.cnblogs.com/zyf-yxm/p/9330761.html
Copyright © 2011-2022 走看看