2012-07-15 56 views
0

appMobi watchPosition和getCurrentPosition失敗,我的小小的GPS圖標出現並繼續,但從appmobi網站複製並粘貼他們的確切示例,我應該至少得到一個警報,如果不是那麼一個錯誤在調試器的控制檯中,我既沒有收到它。appMobi watchPosition getCurrentPosition失敗

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

......

UPDATE

好的,注意到了即使使用有示例中的代碼被分解到一個點。它缺少a)和a;因此,與那些投入了,我現在越來越Uncaught TypeError: Cannot call method 'watchPosition' of undefined

好吧,再次更新

固定的最後一個問題,但是這其中有我stumpped,似乎它運行在2倍回採現在,我需要它只運行一次。我怎麼弄到的?

回答

0

放一個標誌只運行一次:

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

...