Coordinate conversion scheme of DataV dynamic GPS data source on AutoNavi map

Introduction: With the vigorous development of the Internet of Things (IoT), a large amount of data needs to be displayed on the cloud. DataV is a powerful tool for data visualization. You can easily build a beautiful big data screen without building a server. For the display of map coordinates, DataV's current satellite images use AutoNavi's coordinate system, that is, the coordinates of the National Survey Bureau (GCJ-02).
With the vigorous development of the Internet of Things (IoT), a large amount of data needs to be displayed on the cloud. DataV is a powerful tool for data visualization. You can easily build a beautiful big data screen without building a server.

For the display of map coordinates, DataV's current satellite images use AutoNavi's coordinate system, that is, the coordinates of the National Survey Bureau (GCJ-02). For GPS, that is, the latitude and longitude of the WSG84 coordinate system needs to be converted to GCJ-02 coordinates to be displayed correctly on the map.

Here is a coordinate conversion scheme of DataV dynamic GPS data source on AutoNavi map.

For example, there is a positioning card that transfers the data reporting flow to the TableStore through the Link WAN low-power wide area network platform. DataV obtains the data from the TableStore, parses the GPS latitude and longitude information, and displays it on the map.

The GPS coordinates of the location card are 30.13439, 120.0755

The location of the positioning card is as shown in the figure:

If the coordinates are directly connected to the DataV map, there will be a large deviation, as shown in the following figure:

Therefore, a coordinate conversion needs to be done, and the latitude and longitude of the WSG84 coordinate system needs to be converted to GCJ-02 coordinates. On the AutoNavi open platform, you can find online API calls:

Coordinate transformation
However, it is quite troublesome to make API calls in the scripts in DataV. I consulted a classmate of DataV @yunyi and provided an open source conversion method, which can be directly converted locally according to the algorithm.

The script is placed in the filter of the data source. The following is the code including the simplified conversion method and filtering script. If there is a need for coordinate conversion of the DataV dynamic GPS data source on the AutoNavi map, the following simplified conversion method can be copied:

// 以下是简化的转换方法wgs84togcj02
var PI = 3.1415926535897932384626;
var a = 6378245.0;
var ee = 0.00669342162296594323;

function transform_latitude(lng, lat) {
var lat = +lat;
var lng = +lng;
var ret = -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.0;
return ret
};

function transform_longitude(lng, lat) {
var lat = +lat;
var lng = +lng;
var ret = 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.0;
return ret
};

/**
* WGS84 to GCj02
* @param lng
* @param lat
* @returns {*[]}
*/
function wgs84togcj02(lng, lat) {
var lat = +lat;
var lng = +lng;
var dlat = transform_latitude(lng - 105.0, lat - 35.0);
var dlng = transform_longitude(lng - 105.0, lat - 35.0);
var radlat = lat / 180.0 * PI;
var magic = Math.sin(radlat);
magic = 1 - ee * magic * magic;
var sqrtmagic = Math.sqrt(magic);
dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * PI);
dlng = (dlng * 180.0) / (a ​​/ sqrtmagic * Math.cos(radlat) * PI);
var mglat = lat + dlat;
var mglng = lng + dlng;
return [mglng, mglat]
};

// The following is the filter script, calling the wgs84togcj02 conversion method
var output = [];

for (var item in data) {
var d = { "time": "", "longitude": "", "latitude": "", "data": "1", "type": "1" };
var LocatorPayLoadData = data[item].LocatorPayLoadData;

var longitude_degree = parseInt(LocatorPayLoadData.substring(6, 10), 16);
var longitude_minute = parseInt(LocatorPayLoadData.substring(10, 12), 16);
var longitude_second = parseInt(LocatorPayLoadData.substring(12, 16), 16);
var latitude_degree = parseInt(LocatorPayLoadData.substring(16, 18), 16);
var latitude_minute = parseInt(LocatorPayLoadData.substring(18, 20), 16);
var latitude_second = parseInt(LocatorPayLoadData.substring(20, 24), 16);
var date = new Date(parseInt(data[item].time));
var year = date.getFullYear(),
month = date.getMonth() + 1,//month starts from 0
day = date.getDate(),
hour = date.getHours(),
min = date.getMinutes(),
sec = date.getSeconds();
var newTime = year + '-' +
(month < 10 ? '0' + month : month) + '-' +
(day < 10 ? '0' + day : day) + ' ' +
(hour < 10 ? '0' + hour : hour) + ':' +
(min < 10 ? '0' + min : min) + ':' +
(sec < 10 ? '0' + sec : sec);
d.time = newTime;
d.longitude = longitude_degree + longitude_minute / 60 + longitude_second / (3600 * 100);
d.latitude = latitude_degree + latitude_minute / 60 + latitude_second / (3600 * 100);
var longitude_wgs84 = d.longitude.toFixed(6);
var latitude_wgs84 = d.latitude.toFixed(6);
var result = wgs84togcj02(longitude_wgs84, latitude_wgs84);
d.longitude = result[0].toFixed(6)
d.latitude = result[1].toFixed(6)

output.push(d);
}

return output;

the term
WSG84
The World Geodetic System (WGS) is a geodetic system standard used in cartography, geodesy, and navigation (including GPS). WGS contains a set of Earth's standard latitude and longitude coordinate system, a reference ellipsoid for calculating raw altitude data, and a set of gravitational equipotential surface data for defining sea level altitude.

The latest version of WGS is WGS 84 (also known as WGS 1984, EPSG:4326), defined in 1984 and last revised in 2004. [1] Previous versions are WGS 72, WGS 66, WGS 60. GPS uses the WGS 84 reference system.

GCJ-02
The coordinate system released by the National Bureau of Surveying in 2002. Also known as "Mars coordinates". In China, at least the coordinate system of GCJ-02 must be used. For example, Google, Tencent, and AutoNavi are all using this coordinate system.

Related Articles

Explore More Special Offers

  1. Short Message Service(SMS) & Mail Service

    50,000 email package starts as low as USD 1.99, 120 short messages start at only USD 1.00

phone Contact Us