我想在Android上使用地理定位API。我知道有一个被定义的“导航器”对象,应该用来获取用户的位置。所以,我创建了这个示例代码:类和属性问题
function GeolocationTester()
{
// here I want to store all acquired locations
this.locations = new Array();
alert("this.locations defined: " + this.locations);
this.onSuccess = function(position)
{
alert("Entered onSuccess");
alert("this.locations defined: " + this.locations);
}
this.onError = function(error)
{
alert("error acquiring location");
}
navigator.geolocation.watchPosition(this.onSuccess, this.onError, { enableHighAccuracy: true });
}
而且它不适用于我。每当watchPosition调用onSuccess时,this.locations字段没有被定义(并且它在新数组之后被定义)。我知道我做错了什么,但是因为它是我的一个JavaScript尝试,所以不知道是什么。那么,任何人都可以在这里找到问题?