Type of coordinate system

1, WGS84

It is a geodetic coordinate system, which is also used in the GPS global positioning system. Conversion of any coordinate system to WGS84 type is not supported by law

Users: Autonavi, Google, Tencent and other overseas regions, Police Geographic Information System

2, GCJ02

Also known as Mars coordinate system, it is the coordinate system of geographic information system formulated by the State Bureau of Surveying and Mapping of China. The coordinate system encrypted by WGS84 coordinate system.

Users: Autonavi, Tencent, Google

3, BD09

Baidu coordinate system, encrypted again on the basis of GCJ02 coordinate system. Bd09ll represents latitude and longitude coordinates of Baidu and BD09MC represents Mercator metric coordinates of Baidu.

User: Baidu

4. CGCS2000 coordinate system:

The National geodetic coordinate system is a geocentric geodetic coordinate system established by the Continuous operation reference station of China GPS, space geodetic control network and the joint adjustment of astronomical geodetic network and space geodetic network.

2. Coordinate system transformation

1. Baidu Map

Within the territory: using BD09(BD09LL Baidu latitude and longitude coordinates), support WGS84, GCJ02 conversion to BD09, reverse is not supported, and a batch conversion is limited (a single request can batch parse 100 coordinates)

Overseas: Use WGS-84

Conversion API documentation

Lbsyun.baidu.com/index.php?t…

demo

Lbsyun.baidu.com/jsdemo.htm#…

2. Amap

Territory: GCJ02, support WGS84 conversion into GCJ02

Overseas: WGS84

Conversion API documentation

Lbs.amap.com/api/webserv…

Tencent Map

Territory: GCJ02, support other coordinate system batch conversion batch conversion

Overseas: WGS84

4. GPS coordinate conversion API (external network and charge)

www.gpsspg.com/api/convert…

5, openlayer5

EPSG:4326, equivalent to WGS84 coordinate system

EPSG:3857 (default), also known as spherical Mercator or Web Mercator, is a projected coordinate system

Conversion API documentation

Openlayers.org/en/latest/a…

What is PGIS

The initial construction of Police Geographic Information System (Police Geographic Information System) project of the Ministry of Public Security started in 2003. PGIS uses the WGS84 coordinate system

4. PGIS (WGS84) is converted to Baidu coordinates

Conversion API documentation

Lbsyun.baidu.com/index.php?t…

demo

Lbsyun.baidu.com/jsdemo.htm#…

5. Conversion methods between coordinate systems

1. Baidu Map example
import React from 'react'
import logo from './logo.svg'
import mapStyle from './custom_map_config.json'
import Coordtransform from './coordtransform'
import './App.css'const { BMap } = window class App extends React.Component { constructor(props) { super(props) this.loadMap = This.loadmap. bind(this) // WGS84 coordinate this.wgs = {LNG: 116.39117368075213, lat: This. Bd = {LNG: 116.40387397, Lat: 39.91488908}}componentDidMount() {
    this.loadMap()
  }

  converCallback = (map) => (data) => {
    if(data.status === 0) {
      var marker = new BMap.Marker(data.points[0])
      map.addOverlay(marker)
      var label = new BMap.Label("Baidu API conversion (correct)",{offset:new map. Size(20,-10)}) marker.setLabel(label) // Add Label map.setCenter(data.points[0])}}loadMap() {// Load maplet map = new BMap.Map("map-container")
    letCenterPoint = new BMap. Point (116.404, 39.920) map. CenterAndZoom (centerPoint, 16) map. EnableScrollWheelZoom (trueSetmap.setmapstyle ({styleJson: MapStyle}) / / move the map and zoom control. AddControl (new BMap. NavigationControl ()) / / -- -- -- -- -- -- -- -- -- -- -- -- -- -- conversion coordinates start -- -- -- -- -- -- -- -- -- -- -- -- / / Add WGS point (corresponding to Baidu Tian 'anmen position)let pointWGS = new BMap.Point(this.wgs.lng,this.wgs.lat)
    let markerWGS = new BMap.Marker(pointWGS)
    map.addOverlay(markerWGS)
    let labelWGS = new BMap.Label("Original WGS84 coordinates.", {offset: new BMap. Size (20, 10)}) markerWGS. SetLabel (labelWGS) / / -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - custom methods WGS84 - > GCJ02 - > BD09 began ------------- const coord = Coordtransform.wgs84ToGcj02(this.wgs.lng,this.wgs.lat) const coord1 = Coordtransform.gcj02ToBd09(coord[0], coord[1])let pointWGS1 = new BMap.Point(coord1[0],coord1[1])
    let markerWGS1 = new BMap.Marker(pointWGS1)
    map.addOverlay(markerWGS1)
    let labelWGS1 = new BMap.Label("Method to transform transformed GPS coordinates (right) -- -- -- -- -- -- -- -- -- -- -- -- the front was blocking the way conversion WGS84 - > GCJ02 - > BD09 coordinates (right)", {offset: new BMap. Size (20, 10)}) markerWGS1. SetLabel (labelWGS1) / / -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - custom methods WGS84 - > GCJ02 - > BD09 end -- -- -- -- -- -- -- -- -- -- -- -- -- / / -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - custom methods BD09 start - > GCJ02 - > WGS84 start -- -- -- -- -- -- -- -- -- -- -- -- -- const coordbw = Coordtransform.bd09ToGcj02(this.bd.lng,this.bd.lat) const coordbw1 = Coordtransform.gcj02ToWgs84(coordbw[0], coordbw[1])let point2 = new BMap.Point(coordbw1[0],coordbw1[1])
    let marker2 = new BMap.Marker(point2)
    map.addOverlay(marker2)
    let label2 = new BMap.Label("BD09 start - > GCJ02 - > WGS84 (right) -- -- -- -- -- -- -- -- -- -- -- -- the front was blocking the way conversion BD09 - > GCJ02 - > WGS84 coordinates (right but have offset)", {offset: new BMap. Size (20, 10)}) marker2. SetLabel (label2) / / -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - custom methods BD09 start - > GCJ02 - > WGS84 end -- -- -- -- -- -- -- -- -- -- -- -- -- / / -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - baidu API WGS84 - > GCJ02 - > BD09 start -- -- -- -- -- -- -- -- -- -- -- -- -- const convertor = new BMap. Convertor () const pointArr = [] pointArr.push(pointWGS) convertor.translate(pointArr, 1, 5, Enclosing converCallback (map)) / / -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - baidu API WGS84 - > GCJ02 - > BD09 end -- -- -- -- -- -- -- -- -- -- -- -- -- / / -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- conversion coordinates the end -- -- -- -- -- -- -- -- -- -- -- - / / / / var traffic traffic = new BMap. TrafficLayer () / / map addTileLayer (traffic)}render() {
    return (
      <div className="App">
        <h2>Baidu Map Demo</h2>
        <button onClick={this.loadMap}>Load Map</button>
        <div id="map-container"></div>
      </div>
    )
  }
}

export default App
Copy the code

2. Custom methods

Test the following code

WGS84 – > GCJ02 – > BD09 accurately

BD09->GCJ02->WGS84 slightly offset

/* * Function: provides the conversion between baidu coordinates (BD09), National Bureau of Measurement coordinates (Mars coordinates, GCJ02), and WGS84 coordinates. 2019-08-23 10:19:02 * https://www.cnblogs.com/telwanggs/p/10410578.html * / / / define some constants const x_PI 3000.0/180.0 = 3.14159265358979324 * const PI = 3.1415926535897932384626 const a = 6378245.0 const EE = 0.00669342162296594323 class Coordtransform {/** * @param bd_LNG * @param bd_lat * @returns {*[]} */ static bd09ToGcj02(bd_lngString, Bd_latString) {const bd_LNG = +bd_lngString const bd_lat = +bd_latString const x = bd_LNG-0.0065 const y = bd_lat - Sine (y * x_PI) const theta = math.atan2 (y, y, y, y); X) -0.000003 * math. cos(x * x_PI) const gg_LNG = z * math. cos(theta) const gg_Lat = z * math. sin(theta)return[gg_lng, Gg_lat]} /** * @param LNG * @param lat * @returns {*[]} */ static gcj02ToBd09(lngString, latString) { const lng = Number(lngString) const lat = Number(latString) const z = Math.sqrt(lng * lng + lat * lat) + Math.sin(lat * x_PI) const theta = math. atan2(lat, LNG) + 0.000003 * math. cos(LNG * x_PI) const bd_LNG = z * math. cos(theta) + 0.0065 const bd_lat = z * math. sin(theta) + 0.006return[bd_LNG, bd_lat]} /** * WGS84 to GCj02 * @param LNG * @param lat * @returns {*[]} */ static wgs84ToGcj02(lngString, latString) { const lng = Number(lngString) const lat = Number(latString)if (this.outOfChina(lng, lat)) {
            return [lng, lat]
        } 
        letDlat = this. TransformLat (LNG-105.0, LAT-35.0)letDLNG = this. TransformLng (LNG-105.0, LAT-35.0) const Radlat = Lat / 180.0 * PIletMagic = math.sin (radlat) magic = 1 - EE * magic * magic const sqrtMagic = math.sqrt (magic) dlat = (dlat * 180.0)/((a * (1-EE))/(magic * SQrtMagic) * PI) DLNG = (DLNG * 180.0)/(a/SQrtMagic * math. cos(radlat) * PI) const mglat = lat  + dlat const mglng = lng + dlngreturn[MGLNG, mglat]} /** * GCJ02 to WGS84 * @param LNG * @param lat * @returns {*[]} */ static gcj02ToWgs84(lngString, latString) { const lng = Number(lngString) const lat = Number(latString)if (this.outOfChina(lng, lat)) {
            return [lng, lat]
        } 
        letDlat = this. TransformLat (LNG-105.0, LAT-35.0)letDLNG = this. TransformLng (LNG-105.0, LAT-35.0) const Radlat = Lat / 180.0 * PIletMagic = math.sin (radlat) magic = 1 - EE * magic * magic const sqrtMagic = math.sqrt (magic) dlat = (dlat * 180.0)/((a * (1-EE))/(magic * SQrtMagic) * PI) DLNG = (DLNG * 180.0)/(a/SQrtMagic * math. cos(radlat) * PI) const mglat = lat  + dlat const mglng = lng + dlngreturn [lng * 2 - mglng, lat * 2 - mglat]
    }

    static transformLat(lngString, latString) {
        const lng = Number(lngString)
        const lat = Number(latString)
        letRet = -100.0 + 2.0 * LNG + 3.0 * Lat + 0.2 * Lat * Lat + 0.1 * LNG * lat + 0.2 * math.sqRT (math.ABS (LNG)) RET += (20.0 * Math.sin(6.0 * LNG * PI) + 20.0 * math. sin(2.0 * LNG * PI)) * 2.0/3.0 ret += (20.0 * Math.sin(Lat * PI) + 40.0 * Math.sin(lat / 3.0 * PI)) * 2.0/3.0 ret += (160.0 * math.sin (lat / 12.0 * PI) + 320 * math.sin (lat * PI / 30.0)) * 2.0 / 3.0return ret
    }

    static transformLng(lngString, latString) {
        const lng = Number(lngString)
        const lat = Number(latString)
        letRet = 300.0 + LNG + 2.0 * Lat + 0.1 * LNG * LNG + 0.1 * LNG * Lat + 0.1 * math.sqRT (math.ABS (LNG)) RET += (20.0 * Math.sin(6.0 * LNG * PI) + 20.0 * math. sin(2.0 * LNG * PI)) * 2.0/3.0 ret += (20.0 * Math.sin(LNG * PI) + 40.0 * Math.sin(LNG / 3.0 * PI)) * 2.0/3.0 ret += (150.0 * math. sin(LNG / 12.0 * PI) + 300.0 * math. sin(LNG / 30.0 * PI)) * 2.0/3.0returnRet} /** * @param LNG * @param lat * @returns {Boolean} */ static outOfChina(lngString, LatString) {const LNG = Number(lngString) const lat = Number(latString) // Latitude 3.86~53.55, longitude 73.66~135.05return! (LNG > 73.66&& LNG < 135.05&& Lat > 3.86&& Lat < 53.55)}}export default Coordtransform
Copy the code

This paper reference code link: www.cnblogs.com/telwanggs/p…