存儲座標我創建的HTML按鈕:的Javascript地理定位:在陣列
其中齒輪的stLoc()Javascript函數。
我的意圖是存儲vaulesX
陣列內的緯度。
這裏是我的代碼:
var valuesX=[];
//This is to show the current position:
function handleLoc(pos) {
var a=pos.coords.latitude;
var b=pos.coords.longitude;
var p = new L.LatLng(+a, +b);
mark(p);
}
//Here I intend to store the latitude using "valuesX.push":
function stLoc(pos) {
var a=pos.coords.latitude;
var b=pos.coords.longitude;
var p = new L.LatLng(+a, +b);
mark(p);
valuesX.push(a);
}
//And this is to enable the geolocation:
function handleErr(pos) {
document.write("could not determine location");
}
if (navigator.geolocation) {
navigator.geolocation.watchPosition(handleLoc,handleErr);
}
else {
document.write("geolocation not supported");
}
我得到的輸出是一個空數組。
你怎麼居然通過'pos'到'stLoc(pos)'? – Grampa 2012-08-12 09:11:14