高德与百度地图坐标的相互转化(IOS和h5)

2019-03-15 11:17:29 浏览数 (1)

IOS高德坐标转百度

代码语言:javascript复制
 (CLLocationCoordinate2D) bd_decrypt:(double)gg_lat gg_lon:(double)gg_lon
{
    double x = gg_lon, y = gg_lat;
    double z = sqrt(x * x   y * y)   0.00002 * sin(y * x_pi);
    double theta = atan2(y, x)   0.000003 * cos(x * x_pi);
    
    CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(z * sin(theta) 0.006, z * cos(theta) 0.0065);
    return coordinate;
}

IOS百度坐标转高德

代码语言:javascript复制
 (CLLocationCoordinate2D) bd_decrypt:(double)bd_lat bd_lon:(double)bd_lon
{
    double x = bd_lon - 0.0065, y = bd_lat - 0.006;
    double z = sqrt(x * x   y * y) - 0.00002 * sin(y * x_pi);
    double theta = atan2(y, x) - 0.000003 * cos(x * x_pi);
    CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(z * sin(theta), z * cos(theta));
    return coordinate;
}

H5高德坐标转百度

代码语言:javascript复制
function bd_encrypt(bd_lat, bd_lon) {
    var X_PI = Math.PI * 3000.0 / 180.0;
    var x = bd_lon, y = bd_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 gg_lng = z * Math.cos(theta)   0.0065;
    var gg_lat = z * Math.sin(theta)   0.006;
    return {bd_lon: gg_lng,bd_lat: gg_lat};
}

H5百度坐标转高德

代码语言:javascript复制
function bd_decrypt(bd_lat, bd_lon) {
    var X_PI = Math.PI * 3000.0 / 180.0;
    var x = bd_lon - 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 {bd_lat: gg_lat, bd_lon: gg_lng}
}

0 人点赞