[C #] Mars coordinate system (GCJ-02) and Baidu coordinate system (BD-09) Conversion help class,

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.