Students who have done map-related development will definitely encounter such a problem: the same latitude and longitude coordinates are not the same on Baidu Map and Autonavi map.
About coordinate system
We usually use latitude and longitude to represent a geographical location, but for some reasons, the latitude and longitude information we get from different sources may not be in the same coordinate system.
- Autonavi, Tencent and Google Maps in China use the GCJ-02 coordinate system
- Baidu Map uses the bD-09 coordinate system
- The underlying interface (HTML5 Geolocation or ios, Android API) uses the WGS-84 coordinate system to obtain coordinates from the GPS device
Different coordinate systems can vary by tens to hundreds of meters, so when developing map-based products or doing geographic data visualization, we need to correct the deviations between coordinate systems.
Wgs-84 – World Geodetic System
Wgs-84 (World Geodetic System) is the most widely used coordinate System and also the universal coordinate System in the World. The longitude and latitude obtained by GPS devices is the longitude and latitude in the WGS84 coordinate System. Usually the positioning information obtained through the underlying interface is the WGS84 coordinate system.
Gcj-02. – Coordinates of the National Bureau of Investigation
Gcj-02 (G-GUOjia National, C-CEHUI Surveying and Mapping, J-JU Bureau), also known as the Mars Coordinate system, is a geodetic system based on WGS-84 developed by the National Bureau of Surveying and Mapping of China. The obfuscation algorithm used in this coordinate system adds random shifts in latitude and longitude.
According to national regulations, all public geographic data in mainland China must be encrypted with at least GCJ-02, which means that the data we get from the products of domestic companies must be encrypted. Most domestic Internet map providers use THE GCJ-02 coordinate system, including Amap, Google Map China, etc.
Before publication, sale, dissemination, display and use of navigation electronic map, it is necessary to carry out spatial location technology processing. — GB 20263 — 2006 “Basic Requirements of Navigation Electronic Map Security Processing Technology”, 4.1
Bd-09 – Baidu coordinate system
Bd-09 (Baidu, BD) is the geographic coordinate system used by Baidu Map. It adds one more transform to GCJ-02 to protect user privacy. Coordinates obtained from Baidu products are BD-09 coordinate system.
The solution
Baidu Map and Autonavi map both provide some methods to convert coordinates in different coordinate systems, but they both require network requests and have poor performance. During the Spring Festival holiday, I made a library gcoord to do this.
gcoord
Gcoord solves two main problems
- Can convert coordinates between different coordinate systems
- Ability to work with GeoJSON
GeoJSON is a common data format for the geography industry, which is essentially JSON with some conventions for fields.
Gcoord is very simple to use, for example, to obtain a latitude and longitude coordinate from the GPS of a mobile phone and display it on a hundred degree map, you can use GCOORD to convert the current coordinate system from WGS-84 to BD-09
var result = gcoord.transform(
[ 116.403988.39.914266].// Latitude and longitude coordinates
gcoord.WGS84, // Current coordinate system
gcoord.BD09 // Target coordinate system
);
console.log( result ); // [116.41661560068297, 39.92196580126834]
Copy the code
See gCOord’s documentation for details on how to use it
Welcome star