【发布时间】:2012-08-12 09:04:26
【问题描述】:
我创建了一个 HTML 按钮:
...onclick="stLoc();"/>
它支持 stLoc() Javascript 函数。
我的意图是将纬度存储在vaulesXarray 中。
这是我的代码:
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)的?
标签: javascript geolocation coordinates latitude-longitude navigator