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);
}

……

アップデート

わかりました、例を使用してもコードが壊れていることに気付きました。) と ; がありません。だから、それらを入れて、私は今得ていますUncaught TypeError: Cannot call method 'watchPosition' of undefined

わかりました、もう一度更新します

最後の問題を修正しましたが、これは私を困惑させました。今は停止するために2回実行されているようです。1回だけ実行する必要があります。どうすればそれを手に入れることができますか?

4

1 に答える 1

0

フラグを立てて1回だけ実行します。:

    ...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 に答える