2012-03-29 64 views
3

我試圖讓在煎茶觸摸2用戶位置:如何通過GPS獲取用戶位置煎茶

var geo = new Ext.util.Geolocation({ 
     autoUpdate: true, 
     allowHighAccuracy: true, 
     listeners: { 
      locationupdate: function(geo) { 
       lat = geo.getLatitude(); 
       lon = geo.getLongitude(); 

       // here comes processing the coordinates 
      } 
     } 
    }); 

但我只能從網絡中得到了座標。 Android設備上沒有GPS圖標,指出我正在使用GPS。當我關閉互聯網連接時,它也不起作用。我如何啓用GPS定位?在清單文件中啓用GPS。

回答

1

我剛剛得到了這一點。

原來有一個在煎茶了一個錯誤:在Ext.util.Geolocation.parseOption他們命名參數allowHighAccuracythe w3c specs命名爲enableHighAccuracy。 我下面的代碼添加到我的應用程序初始化來解決這個問題:

var parseOptions = function() { 
    var timeout = this.getTimeout(), 
     ret = { 
      maximumAge: this.getMaximumAge(), 
      // Originally spells *allowHighAccurancy* 
      enableHighAccuracy: this.getAllowHighAccuracy() 
     }; 

    //Google doesn't like Infinity 
    if (timeout !== Infinity) { 
     ret.timeout = timeout; 
    } 
    return ret; 
}; 
Ext.util.Geolocation.override('parseOptions', parseOptions); 

對於記錄:錯誤has been reported over a year agothe fix was applied for TOUCH-2804 in a recent build。我不知道這意味着什麼,但肯定這個錯誤仍然在2.0

編輯:使用上面提到的方法也不能很好地工作。隨着Exts使用setInterval重複調用getCurrentPosition,GPS圖標會打開和關閉。這樣做的原因是The native watchPosition method is currently broken in iOS5。在我的Android目標應用程序中,我最終放棄了Ext:util.Geolocation並直接使用了navigator.geolocation.watchPosition。之後,它就像一個魅力。

+1

是的,我最終還是使用了Phonegap的navigator.geolocation.watchPosition – 2012-06-14 12:17:14

+1

這個bug已經修復爲2.02 for enableHighAccuracy並且可用於支持訂閱者,下一個公開發布版本是2.1 – 2012-08-15 16:28:53

0

GPS位置提供者使用衛星確定位置。根據條件,此提供程序可能需要一段時間才能返回定位修復。 需要權限android.permission.ACCESS_FINE_LOCATION。

+0

是的,這個權限被添加。但GPS不使用,並關閉互聯網** locationupdate **根本不會被調用。 – 2012-03-29 12:48:54

+0

請參閱此鏈接:http://developer.android.com/reference/android/webkit/GeolocationPermissions.html以及http://developer.android.com/guide/topics/location/obtaining-user-location.html – Nimit 2012-03-29 13:34:59

+1

我需要不使用純Java訪問這些功能,而是使用Sencha框架。 – 2012-03-30 05:24:50

0

嘿我想你需要更新的經度和緯度值。

請點擊此鏈接.. Click Here

我已經嘗試過了,在Android手機。它的工作進行測試。

注意:必須和應該在Android手機上測試GPS狀態。它不會在eclipse模擬器上顯示。但它會顯示在手機上試試..

有一個不錯的。

+1

有趣的信息,但它也適用於純Java。我在Sencha框架中開發,我需要通過這個框架訪問GPS。在文檔中他們說Ext.util.Geolocation自動使用GPS,但我無法實現。 – 2012-04-02 11:29:31