<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;}
#l-map{height:100%;width:78%;float:left;border-right:2px solid #bcbcbc;}
#r-result{height:100%;width:20%;float:left;}
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.5&ak=E2e5a8af567e7bb2e3a9892e1006c505">
</script>
<title>
测算两点的距离
</title>
</head>
<body>
<div id="allmap">
</div>
</body>
</html>
<script type="text/javascript">
var map = new BMap.Map("allmap"); // 创建Map实例
var mPoint = new BMap.Point(102.752495, 25.047873); //第一个点
map.enableScrollWheelZoom();
map.centerAndZoom(mPoint, 14);
var pointA = mPoint;
map.addEventListener("click", clickMap);
function clickMap(e) {
if (e.target == map.getOverlays()) {
return;
}
var pointB = new BMap.Point(e.point.lng, e.point.lat); //点击的作为第二个点
alert('距离为:' + map.getDistance(pointA, pointB) + '米'); //弹出测距后的值
/*var polyline = new BMap.Polyline([pointA, pointB], {
strokeColor: "blue",
strokeWeight: 6,
strokeOpacity: 0.5
});
//定义折线
map.addOverlay(polyline);*/
}
</script>
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。