Key code:
usingSystem;usingYanZhiwei.DotNet2.Utilities.Models;namespaceyanzhiwei.dotnet2.utilities.common{// <summary> /// Mars coordinate system (GCJ-02) and Baidu coordinate system (BD-09) Conversion helper class // </summary> Public classBdgcjlatlonhelper {/** Reference:*bd09 coordinate system: that is, the Baidu coordinate system, GCJ02 coordinate system after the encrypted coordinate system. */ #regionConstantConst DoubleX_PI = 3.14159265358979324 * 3000.0/180.0;#endregion #regionConvert GCJ-02 coordinates to BD-09 coordinates// <summary> /// convert GCJ-02 coordinates to BD-09 coordinates // </summary> /// <param name= "gcjpoint" >gcj-02 coordinates </param> // <returns>bd-09 coordinates </returns> PublicLatlngpoint gcj02tobd09 (Latlngpoint gcjpoint) {Latlngpoint _bdpoint =NewLatlngpoint ();Double_x = Gcjpoint.lonx, y = gcjpoint.laty;Double_z = math.sqrt (_x * _x + y * y) + 0.00002 * Math.sin (y * x_pi);Double_theta = Math.atan2 (y, _x) + 0.000003 * Math.Cos (_x * x_pi); _bdpoint.lonx = _z * Math.Cos (_theta) + 0.0065; _bdpoint.laty = _z * Math.Cos (_theta) + 0.006;return_bdpoint; }#endregion #regionConvert BD-09 coordinates to GCJ-02 coordinates// <summary> /// convert BD-09 coordinates to GCJ-02 coordinates // </summary> /// <param name= "bdpoint" >bd-09 coordinates </param> // <returns>gcj-02 coordinates </returns> PublicLatlngpoint bd09togcj02 (Latlngpoint bdpoint) {Latlngpoint _gcjpoint =NewLatlngpoint ();Double_x = bdpoint.lonx-0.0065, _y = bdpoint.laty-0.006;Double_z = math.sqrt (_x * _x + _y * _y)-0.00002 * Math.sin (_y * x_pi);Double_theta = Math.atan2 (_y, _x)-0.000003 * Math.Cos (_x * x_pi); _gcjpoint.lonx = _z * Math.Cos (_theta); _gcjpoint.laty = _z * Math.sin (_theta);return_gcjpoint; }#endregion}}
[C #] Mars coordinate system (GCJ-02) and Baidu coordinate system (BD-09) Conversion helper class