美文网首页IOS 开发
高德与百度地图坐标的相互转化(IOS和h5)

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

作者: honey缘木鱼 | 来源:发表于2019-03-08 18:11 被阅读6次

IOS高德坐标转百度

+(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百度坐标转高德

+(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高德坐标转百度

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百度坐标转高德

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}
}

相关文章

网友评论

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

    本文链接:https://www.haomeiwen.com/subject/llkdpqtx.html