mysql 百度坐标转换成高德坐标

算法:

    //百度坐标转高德(传入经度、纬度)
function bd_decrypt(bd_lng, bd_lat) {
    var X_PI = Math.PI * 3000.0 / 180.0;
    var x = bd_lng - 0.0065;
    var y = bd_lat - 0.006;
    var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * X_PI);
    var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * X_PI);
    var gg_lng = z * Math.cos(theta);
    var gg_lat = z * Math.sin(theta);
    return {lng: gg_lng, lat: gg_lat}
}
//高德坐标转百度(传入经度、纬度)
function bd_encrypt(gg_lng, gg_lat) {
    var X_PI = Math.PI * 3000.0 / 180.0;
    var x = gg_lng, y = gg_lat;
    var z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * X_PI);
    var theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * X_PI);
    var bd_lng = z * Math.cos(theta) + 0.0065;
    var bd_lat = z * Math.sin(theta) + 0.006;
    return {
        bd_lat: bd_lat,
        bd_lng: bd_lng
    };
}

SQL:

SELECT ROUND((SQRT((xlongitude - 0.0065) * (xlongitude - 0.0065) + (ylatitude - 0.006) * (ylatitude - 0.006)) + 0.00002 * SIN((ylatitude - 0.006) * 3.14159265358979324 * 3000.0 / 180.0) )
* COS(ATAN2((ylatitude - 0.006), (xlongitude - 0.0065)) + 0.000003 * COS((xlongitude - 0.0065) * 3.14159265358979324 * 3000.0 / 180.0)),6)  AS gaode_lon,
ROUND((SQRT((xlongitude - 0.0065) * (xlongitude - 0.0065) + (ylatitude - 0.006) * (ylatitude - 0.006)) + 0.00002 * SIN((ylatitude - 0.006) * 3.14159265358979324 * 3000.0 / 180.0) )
* SIN(ATAN2((ylatitude - 0.006), (xlongitude - 0.0065)) + 0.000003 * COS((xlongitude - 0.0065) * 3.14159265358979324 * 3000.0 / 180.0)),6)  AS gaode_lat
 FROM `t_zuobiao` WHERE   mapType = '百度地图'

 

你可能感兴趣的:(mysql 百度坐标转换成高德坐标)