gps 经纬度 转换实际距离

<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
</head>

<body>
<script src="https://webapi.amap.com/maps?v=1.4.6&key=e163cbe37323c268a52d856b3acbfef"></script>
<script type="text/javascript">
getPosition("117.133676", "36.66844")
//x:经度 y:纬度
function getPosition(x, y) {
var gps = []//[, 36.66844];
gps.push(x)
gps.push(y)
AMap.convertFrom(gps, 'gps', function (status, result) {
if (result.info === 'ok') {
var lnglats = result.locations; // Array.<LngLat>
console.log(JSON.stringify(lnglats))
var xx = lnglats[0]["O"];
var yy = lnglats[0]["P"];
AMap.service('AMap.Geocoder', function () {
geocoder = new AMap.Geocoder({});
var lnglatXY = [xx, yy];
geocoder.getAddress(lnglatXY, function (status, result) {
if (status === 'complete' && result.info === 'OK') {
console.log(JSON.stringify(result,null,4));
} else {
alert("获取地址失败,状态:" + status + "info:" + result.info)
}
});
})
}
});
}
</script>
</body>

</html>

转载于:https://www.cnblogs.com/liuhao-web/p/9329918.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值