function toAMap(lng, lat) {
const X_PI = Math.PI * 3000.0 / 180.0;
let x = lng - 0.0065;
let y = lat - 0.006;
let z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * X_PI);
let theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * X_PI);
let amap_lng = z * Math.cos(theta);
let amap_lat = z * Math.sin(theta);
return {
lng: amap_lng,
lat: amap_lat
}
}//高德官方方法批量转换
var lnglats = [
{lng: 120.079833, lat: 30.316997},
{lng: 120.101293, lat: 30.334685},
{lng: 120.100079, lat: 30.338022}
];
for(let p of lnglats){
AMap.convertFrom([p.lng, p.lat], 'baidu', function (status, result) {
if (result.info === 'ok') {
p.lng = result.locations[0].lng;
p.lat = result.locations[0].lat;
}
});
}高德地图坐标转百度地图坐标:
function toBaiduMap(lng, lat) {
const X_PI = Math.PI * 3000.0 / 180.0;
let x = lng;
let y = lat;
let z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * X_PI);
let theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * X_PI);
let bd_lng = z * Math.cos(theta) + 0.0065;
let bd_lat = z * Math.sin(theta) + 0.006;
//console.log(bd_lng+","+bd_lat);
return {
lng: bd_lng,
lat: bd_lat
};
}常用链接
[1].百度地图坐标拾取:http://api.map.baidu.com/lbsapi/getpoint/index.html
[2].高德地图坐标拾取:https://lbs.amap.com/tools/picker
[3].腾讯地图坐标拾取:http://api.map.baidu.com/lbsapi/getpoint/index.html
评论(0)
暂无评论。