0
我有問題,也許有人可以幫助我。 這是我的代碼:當我試圖計算距離時,我可以使用我的函數爲正常變量,我給它:document.write(getDistance(45,35,41,35));
但是當我從我的矩陣調用 不工作,你知道什麼是問題嗎? document.write(getDistance(parseFloat($m.rows[0][3]),parseFloat($m.rows[1][3]),parseFloat($m.rows[0][4]),parseFloat($m.rows[1][4])));
Javascript矩陣和距離計算
TNX
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
</head>
<script type="text/javascript">
function Matrix() {
this.rows = new Array();
}
var $m = new Matrix();
$m.rows[0] = new Array(1, 10, 45,41);
$m.rows[1] = new Array(2, 5, 35,35);
$m.rows[2] = new Array(3, 8, 41,40);
alert($m.rows[1][2]);
//Calculate the shortest distance based on lat and long
function getDistance(lat1, lat2, lon1, lon2){
var R = 6371; //KM
var d = Math.acos(Math.sin(lat1) * Math.sin(lat2) +
Math.cos(lat1) * Math.cos(lat2) * Math.cos(lon2 - lon1)) * R
return d
};
document.write(getDistance(parseFloat($m.rows[0][3]),parseFloat($m.rows[1][3]),parseFloat($m.rows[0][4]),parseFloat($m.rows[1][4])));
document.write(getDistance(45,35,41,35));
</SCRIPT>
</BODY>
</HTML>