js版谷歌地图计算两经纬度坐标点的距离

 球面上两点间大圆劣弧的距离

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>谷歌地图计算两经纬度坐标点的距离</title>
<script type="text/javascript">
	var EARTH_RADIUS = 6378.137; //地球半径

	//将用角度表示的角转换为近似相等的用弧度表示的角 java Math.toRadians
	function rad(d) {
		return d * Math.PI / 180.0;
	}

	/**
	 * 谷歌地图计算两个坐标点的距离
	 * @param lng1	经度1
	 * @param lat1	纬度1
	 * @param lng2	经度2
	 * @param lat2	纬度2
	 * @return 距离(千米)
	 */
	function getDistance(lng1, lat1, lng2, lat2) {
		var radLat1 = rad(lat1);
		var radLat2 = rad(lat2);
		var a = radLat1 - radLat2;
		var b = rad(lng1) - rad(lng2);
		var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)
				+ Math.cos(radLat1) * Math.cos(radLat2)
				* Math.pow(Math.sin(b / 2), 2)));
		s = s * EARTH_RADIUS;
		s = Math.round(s * 10000) / 10000;
		return s;
	}
	
	alert(getDistance(116.403933,39.914147, 116.403237,39.927919));
</script>
</head>
<body>

</body>
</html>

 

java版谷歌地图计算两经纬度坐标点的距离

http://happyqing.iteye.com/blog/2236103

 

你可能感兴趣的:(js,距离,经纬度,谷歌,坐标点)