eviltransform

repository·master·Indexed 25 days ago

https://github.com/googollee/eviltransform

A multi-language library for transforming coordinates between the standard WGS-84 (Earth) system and the GCJ-02 (Mars/China) coordinate system used by major Chinese map services. It provides functions for WGS-84 to GCJ-02 conversion, high-precision GCJ-02 to WGS-84 conversion (accuracy < 0.5m), and conversions between GCJ-02 and BD-09 (Baidu). The library also includes a utility to calculate the distance between two geographic points in meters. Supported languages include Go, JavaScript, Python, C/C++/Obj-C, C#, PHP, and Haskell.

Tokens
1.2K
Snippets
4
Records
13
Agent score
82%

What's inside eviltransform

  1. Convert WGS-84 to GCJ-02 (WGStoGCJ)

    master

    Convert standard Earth coordinates (WGS-84) to the GCJ-02 coordinate system (often called 'Mars Coordinates'), which is used by services like Google Maps and Autonavi Map in China.

    Note: Baidu Maps uses an additional offset based on GCJ-02, so this conversion alone may not be sufficient for Baidu.

    // Go/Golang
    func WGStoGCJ(wgsLat, wgsLng float64) (gcjLat, gcjLng float64)
  2. Convert GCJ-02 to WGS-84 (GCJtoWGS)

    master

    Convert GCJ-02 coordinates back to standard WGS-84 Earth coordinates.

    Accuracy: The output accuracy is approximately 1m to 2m. If higher precision is required, use GCJtoWGSExact instead.

    // Go/Golang
    func GCJtoWGS(gcjLat, gcjLng float64) (wgsLat, wgsLng float64)
  3. Convert GCJ-02 to WGS-84 with high precision (GCJtoWGSExact)

    master

    Convert GCJ-02 coordinates to WGS-84 Earth coordinates with high precision.

    Accuracy: The output accuracy is less than 0.5m. Performance: This method is significantly slower than the standard GCJtoWGS method.

    // Go/Golang
    func GCJtoWGSExact(gcjLat, gcjLng float64) (wgsLat, wgsLng float64)
  4. API Reference by Language

    master

    The following is a summary of the available transformation and distance functions across supported languages.

    Go/Golang

    • WGStoGCJ(wgsLat, wgsLng float64) (gcjLat, gcjLng float64)
    • GCJtoWGS(gcjLat, gcjLng float64) (wgsLat, wgsLng float64)
    • GCJtoWGSExact(gcjLat, gcjLng float64) (wgsLat, wgsLng float64)
    • Distance(latA, lngA, latB, lngB float64) float64

    JavaScript/Python

    • eviltransform.wgs2gcj(wgsLat, wgsLng)
    • eviltransform.gcj2wgs(gcjLat, gcjLng)
    • eviltransform.gcj2wgs_exact(gcjLat, gcjLng)
    • eviltransform.distance(latA, lngA, latB, lngB) Note: JavaScript output for coordinate conversions is an object: {"lat": xx.xxxx, "lng": yy.yyyy}.

    C/C++/Obj-C

    • void wgs2gcj(double wgsLat, double wgsLng, double *gcjLat, double *gcjLng)
    • void gcj2wgs(double gcjLat, double gcjLng, double *wgsLat, double *wgsLnt)
    • void gcj2wgs_exact(double gcjLat, double gcjLng, double *wgsLat, double *wgsLnt)
    • double distance(double latA, double lngA, double latB, double lngB)

    CSharp

    • EvilTransform.Transform.WGS2GCJ(wgsLat, wgsLng)
    • EvilTransform.Transform.GCJ2WGS(gcjLat, gcjLng)
    • EvilTransform.Transform.GCJ2WGSExact(gcjLat, gcjLng)
    • EvilTransform.Transform.Distance(latA, lngA, latB, lngB)

    PHP5.4+

    • \larryli\eviltransform\EvilTransform::WGStoGCJ($wgsLat, $wgsLng)
    • \larryli\eviltransform\EvilTransform::GCJtoWGS($gcjLat, $gcjLng)
    • \larryli\eviltransform\EvilTransform::GCJtoWGSExact($gcjLat, $gcjLng)
    • \larryli\eviltransform\EvilTransform::Distance($latA, $lngA, $latB, $lngB)

    Haskell

    • wgs2Gcj (gcjLat, gcjLng)
    • gcj2Wgs (gcjLat, gcjLng)
    • gcj2WgsExact (gcjLat, gcjLng)
    • distance (lat, lng)
  5. Convert GCJ-02 to WGS-84 using `gcj2wgs`

    master
    Use gcj2wgs to convert coordinates from the GCJ-02 (Mars in China) system back to the standard WGS-84 (Earth) system. This method is optimized for speed but has an accuracy of approximately 1m to 2m. If the coordinates are outside the China boundary, the original coordinates are returned.
  6. Convert WGS-84 to GCJ-02 using `wgs2gcj`

    master
    Use wgs2gcj to convert coordinates from the standard WGS-84 (Earth) system to the GCJ-02 (Mars in China) coordinate system. If the provided coordinates are outside the defined China boundary, the function returns the original coordinates unchanged.