0

appMobi watchPosition 和 getCurrentPosition 失败,我的小 GPS 图标出现并继续,但是从 appmobi 站点复制和粘贴以他们的确切示例为例,我至少应该得到一个警报,如果不是,那么调试器控制台中的错误我都没有。

var options = {timeout: 10000, maximumAge: 11000, enableHighAccuracy: true };
//This function is called on every iteration of the watch Position command that fails
var fail = function(){
  alert("Geolocation failed. \nPlease enable GPS in Settings.");
};

//This function is called on every iteration of the watchPosition command that is a success
var suc = function(p){
  alert("Moved To: Latitude:" + p.coords.latitude + "Longitude: " + p.coords.longitude;
};

//This command starts watching the geolocation
var geolocationWatchTimer = AppMobi.geolocation.watchPosition(suc,fail,options);

//Call the stopGeolocation function to stop the geolocation watch
var stopGeolocation = function(){
        AppMobi.geolocation.clearWatch(geolocationWatchTimer);
}

……

更新

好的,注意到即使使用那里的示例代码也被破坏了。它缺少 a ) 和 a ; 所以有了这些,我现在得到Uncaught TypeError: Cannot call method 'watchPosition' of undefined

好的,再次更新

修复了最后一个问题,但这个问题让我很困惑,似乎它运行了 2 次是为了现在停止,我需要它只运行一次。我怎么能得到那个?

4

1 回答 1

0

放置一个标志只运行一次。:

    ...lat=0;
var suc = function(p){
    if ((p.coords.latitude != undefined)&&(lat==0))
    {
            console.log(p.coords.latitude);
            lat=p.coords.latitude;

...

于 2013-01-29T01:10:22.820 回答