GPS/百度/火星坐标转换
关于坐标3个:
GPS坐标:WGS84
百度坐标(BD09)
国测局坐标/火星坐标:GCJ02
下面的 (x,y)是GPS坐标
var x = 115.778676;
var y = 33.844582;
//GPS坐标转换百度坐标
var ggPoint = new BMap.Point(x, y);
//坐标转换完之后的回调函数
translateCallback = function(data) {
if (data.status === 0) {
var marker = new BMap.Marker(data.points[0]);
var label = new BMap.Label({ offset: new BMap.Size(20, -10) });
marker.setLabel(label); //添加百度label
//转换完后的百度坐标
console.log(data.points[0].lng);
console.log(data.points[0].lat);
}
}
setTimeout(function(){
var convertor = new BMap.Convertor();
var pointArr = [];
pointArr.push(ggPoint);
convertor.translate(pointArr, 1, 5, translateCallback);
},1000)