<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<title>两点间距离</title>
<link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css" />
<style>
html,body,#container{
height:100%;
}
</style>
</head>
<body>
<div id="container" style="display:none"></div>
<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=你的高德地图key"></script>
<script type="text/javascript">
//初始化地图对象,加载地图
var map = new AMap.Map("container", {
resizeEnable: true,
zoom: 13
});
var m1 = new AMap.Marker({
map: map,
position: new AMap.LngLat(116.368904, 39.923423)
});
var m2 = new AMap.Marker({
map: map,
position:new AMap.LngLat(116.387271, 39.922501)
});
var p1 = m1.getPosition();
var p2 = m2.getPosition();
var distance = Math.round(p1.distance(p2));
console.log('两点距离:',distance);
</script>
</body>
</html>