java gps经纬度坐标转高德坐标_其他坐标 -> 高德坐标 (批量)

本文介绍了如何使用AMap API实现GPS坐标和高德坐标之间的转换,并通过JavaScript代码展示了如何在网页地图上动态显示转换后的路径和坐标。使用了AMap.Map和AMap.convertFrom函数来实现实时坐标转换。
摘要由CSDN通过智能技术生成
其他坐标变换成高德坐标

html,body,#container{

height:100%;

width:100%;

}

.btn-box{

position: absolute;

right: 5rem;

top: 5rem;

}

.btn{

background: '#0277bd';

width:14em;

margin-left:3.2rem;

margin-top: 0.8rem;

}

坐标批量转换
GPS 坐标转为高德坐标
图吧坐标转为高德坐标
百度坐标转为高德坐标

var map = new AMap.Map("container", {

resizeEnable: true,

center: [116.388904,39.913423],

zoom: 14

});

var $ = function(elementId){

return document.getElementById(elementId);

};

var lnglats = [

'116.368904,39.913423',

'116.398258,39.904600'

];

// 创建包含4个节点的折线及文字标注

var path = [

new AMap.LngLat(116.368904,39.913423),

new AMap.LngLat(116.398258,39.904600)

];

// 创建折线实例

var polyline = new AMap.Polyline({

path: path,

borderWeight: 2, // 线条宽度,默认为 1

strokeColor: 'red', // 线条颜色

lineJoin: 'round' // 折线拐点连接处样式

});

// 将折线添加至地图实例

map.add(polyline);

var text1 = new AMap.Text({

position: new AMap.LngLat(116.368904,39.913423),

text: 'gps坐标',

offset: new AMap.Pixel(-20, -20)

})

map.add(text1);

var polyline2;

var text2;

// 坐标转换

AMap.convertFrom(path, 'gps', function (status, result) {

if (result.info === 'ok') {

var path2 = result.locations;

polyline2 = new AMap.Polyline({

path: path2,

borderWeight: 2, // 线条宽度,默认为 1

strokeColor: 'blue', // 线条颜色

lineJoin: 'round' // 折线拐点连接处样式

});

map.add(polyline2);

text2 = new AMap.Text({

position: result.locations[0],

text: '高德坐标',

offset: new AMap.Pixel(-20, -20)

})

map.add(text2);

}

});

function setCoordinate() {

var type = this.id;

var m1Text = "GPS 坐标";

if(type == 'mapbar'){

m1Text = '图吧坐标';

}else if(type == 'baidu'){

m1Text = '百度坐标';

}

map.remove(polyline2);

map.remove(text2);

text1.setText(m1Text);

// 坐标转换

AMap.convertFrom(path, type, function (status, result) {

if (result.info === 'ok') {

var path2 = result.locations;

polyline2 = new AMap.Polyline({

path: path2,

borderWeight: 2, // 线条宽度,默认为 1

strokeColor: 'blue', // 线条颜色

lineJoin: 'round' // 折线拐点连接处样式

});

map.add(polyline2);

text2 = new AMap.Text({

position: result.locations[0],

text: '高德坐标',

offset: new AMap.Pixel(-20, -20)

})

map.add(text2);

}

});

}

//绑定radio点击事件

var radios = document.querySelectorAll("#coordinate input");

radios.forEach(function(ratio) {

ratio.onclick = setCoordinate;

});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值