coordtransform 0.2.0

Provide mutual conversions between Baidu Coordinate System (BD09), Mars Coordinate System (GCJ02), and WGS84 Coordinate System.
Documentation

coordtransform-rs

Crates.io Documentation License: MIT

提供百度坐标系(BD09)、火星坐标系(国测局坐标系、GCJ02)、WGS84坐标系的相互转换,基于 Rust 语言,无特殊依赖。 Provides mutual conversion between Baidu Coordinate System (BD09), Mars Coordinate System (GCJ02), and WGS84 Coordinate System, implemented in Rust with no special dependencies.

这是 Go版本 的 Rust 移植版本。 This is the Rust port of the Go version.

坐标系说明 Coordinate System Description

  • WGS84坐标系:即地球坐标系,国际上通用的坐标系
  • WGS84 Coordinate System: The Earth coordinate system, commonly used internationally.
  • GCJ02坐标系:即火星坐标系,WGS84坐标系经加密后的坐标系。Google Maps,高德在用
  • GCJ02 Coordinate System: Also known as the Mars coordinate system, an encrypted version of the WGS84 coordinate system. Used by Google Maps and Amap.
  • BD09坐标系:即百度坐标系,GCJ02坐标系经加密后的坐标系
  • BD09 Coordinate System: Also known as the Baidu coordinate system, an encrypted version of the GCJ02 coordinate system.

功能特性 Features

  • 火星坐标系 -> 百度坐标系 (gcj02_to_bd09)
  • 百度坐标系 -> 火星坐标系 (bd09_to_gcj02)
  • WGS84坐标系 -> 火星坐标系 (wgs84_to_gcj02)
  • 火星坐标系 -> WGS84坐标系 (gcj02_to_wgs84)
  • WGS84坐标系 -> 百度坐标系 (wgs84_to_bd09)
  • 百度坐标系 -> WGS84坐标系 (bd09_to_wgs84)

安装 Installation

在你的 Cargo.toml 中添加 Add the following to your Cargo.toml

[dependencies]
coordtransform = "0.1.0"

快速开始 Quick Start

use coordtransform::*;

fn main() {
    // 百度坐标系 -> 火星坐标系
    let (lon, lat) = bd09_to_gcj02(116.404, 39.915);
    println!("BD09 to GCJ02: ({}, {})", lon, lat);

    // 火星坐标系 -> 百度坐标系
    let (lon, lat) = gcj02_to_bd09(116.404, 39.915);
    println!("GCJ02 to BD09: ({}, {})", lon, lat);

    // WGS84坐标系 -> 火星坐标系
    let (lon, lat) = wgs84_to_gcj02(116.404, 39.915);
    println!("WGS84 to GCJ02: ({}, {})", lon, lat);

    // 火星坐标系 -> WGS84坐标系 gcj02 -> WGS84
    let (lon, lat) = gcj02_to_wgs84(116.404, 39.915);
    println!("GCJ02 to WGS84: ({}, {})", lon, lat);

    // 百度坐标系 -> WGS84坐标系
    let (lon, lat) = bd09_to_wgs84(116.404, 39.915);
    println!("BD09 to WGS84: ({}, {})", lon, lat);

    // WGS84坐标系 -> 百度坐标系
    let (lon, lat) = wgs84_to_bd09(116.404, 39.915);
    println!("WGS84 to BD09: ({}, {})", lon, lat);
}

基准测试 Benchmarking

运行基准测试 Run the benchmark tests:

cargo bench

测试 Testing

运行测试 Run the tests:

cargo test

许可证 License

本项目采用 MIT 许可证 - 查看 LICENSE 文件了解详情。 This project is licensed under the MIT License - see the LICENSE file for details.

相关项目 Related Projects