Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New method gcj02_to_bd09 #62

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ pub fn gcj2wgs(gcj_lat: f64, gcj_lng: f64) -> (f64, f64) {
(gcj_lat-d_lat, gcj_lng-d_lng)
}

const X_PI: f64 = std::f64::consts::PI * 3000.0 / 180.0;
// gcj2bd09 convert GCJ-02 coordinate to BD09 coordinate(https://lbsyun.baidu.com/index.php?title=jspopular/guide/coorinfo)
// https://gist.github.com/jp1017/71bd0976287ce163c11a7cb963b04dd8
pub fn gcj02_to_bd09(gcj_lat: f64, gcj_lng: f64) -> (f64, f64) {
let z = (gcj_lng * gcj_lng + gcj_lat * gcj_lat).sqrt() + 0.00002 * (gcj_lat * X_PI).sin();
let theta = gcj_lat.atan2(gcj_lng) + 0.000003 * (gcj_lng * X_PI).cos();
(z * theta.sin() + 0.006, z * theta.cos() + 0.0065)
}

// gcj2wgs_exact convert GCJ-02 coordinate(gcj_lat, gcj_lng) to WGS-84 coordinate.
// The output WGS-84 coordinate's accuracy is less than 0.5m, but much slower than gcj2wgs.
pub fn gcj2wgs_exact(gcj_lat: f64, gcj_lng: f64) -> (f64, f64) {
Expand Down