[C #] Mars coordinate system (GCJ-02) and Baidu coordinate system (BD-09) Conversion help class,
Key code:
Using System; using YanZhiwei. dotNet2.Utilities. models; namespace YanZhiwei. dotNet2.Utilities. common {// <summary> // The Mars coordinate system (GCJ-02) and the Baidu coordinate system (BD-09) conversion help class // </summary> public class BDGCJLatLonHelper {/** reference: * BD09 Coordinate System: Baidu coordinate system, and GCJ02 coordinate system encrypted coordinate system. */# Region constant const double x_pi = 3.14159265358979324*3000.0/180.0; # endregion # region convert the GCJ-02 to the BD-09 coordinate /// <summary> // convert the GCJ-02 to the BD-09 coordinate /// </summary> /// <param name =" gcjPoint "> GCJ-02 coordinates </param> // <returns> BD-09 coordinates </returns> public LatLngPoint GCJ02ToBD09 (LatLngPoint gcjPoint) {LatLngPoint _ bdPoint = new LatLngPoint (); 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 # region convert the BD-09 to the GCJ-02 coordinate /// <summary> // convert the BD-09 to the GCJ-02 coordinate /// </summary> /// <param name =" bdPoint "> BD-09 coordinates </param> // <returns> GCJ-02 coordinates </returns> public LatLngPoint BD09ToGCJ02 (LatLngPoint bdPoint) {LatLngPoint _ gcjPoint = new LatLngPoint (); 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 }}