appMobi watchPosition getCurrentPosition fail

appMobi watchPosition getCurrentPosition fail

本文关键字:fail getCurrentPosition watchPosition appMobi      更新时间:2023-09-26

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次是为了停止,我只需要它运行一次。我怎么能拿到?

只运行一次标志

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