ユーザーの位置情報を取得するためにアプリで sencha-touch 2.0 と phonegap 2.0.0 を使用しています。私のlocahostで実行すると、すべて正常に動作します。ただし、.apk を Android 15 API のデバイス (Eclipse と adt プラグインを使用) にロードすると、getCurrentLocation または watchPosition へのすべての呼び出しが返されません...
ここに私のコードがあります:
geoOn: function(){
    var geoReady = navigator.geolocation || undefined;
    var onSuccess = function(position){
            Top5.app.alert('Geolocation success '+String(position.coords.latitude) + ' ' + String(position.coords.longitude),'Geolocation');
            var scope = Ext.getCmp('nestedList');
            scope.updateDistance(position.coords);
    };
    var onFailure = function(error){Top5.app.alert('Geolocation failed: '+String(error.code) + ' '+String(error.message),'Geolocation');};
    if (geoReady) {
        this.watchId = navigator.geolocation.watchPosition(onSuccess ,onFailure,{timeout:6000,maximumAge: 3000,enableHighAccuracy: true});    
    }
    else{
        Ext.device.Geolocation.watchPosition({
                 frequency: 3000, // Update every 3 seconds
                 callback: function(position) {
                        this.updateDistance(position.coords);
                 },
                 failure: function() {
                   console.log('Geolocation Failure!');
                 },
                 scope:this
        });
    }
 },
 geoGet: function(){
     var geoReady = navigator.geolocation || undefined;
     if (geoReady) {
         var onSuccess = function(position){
             Top5.app.alert('Geolocation successful!!!');
             var scope = Ext.getCmp('nestedList');
             scope.updateDistance(position.coords);          
         };
         var onFailure = function(error){Top5.app.alert('Geolocation failed: '+String(error.code) + ' '+String(error.message),'Geolocation');};
         navigator.geolocation.getCurrentPosition(onSuccess,onFailure);
     }
     else{}
 },
 geoOff:function(){
     var geoReady = navigator.geolocation || undefined;
     if (geoReady) {
         navigator.geolocation.clearWatch(this.watchId);
         this.watchId = null;
     }
     else{
         Ext.device.Geolocation.clearWatch();
     }
 },
 updateDistance:function(coords){
     Top5.app.alert('updateDist','');
     var scope = Ext.getCmp('nestedList');
     var lat = coords.latitude,lon = coords.longitude;
     var store = scope.getStore();
     var i,record;
     for(i = 0; i < store.data.all.length; i++)
     {
         record = store.data.all[i];
         if(record.data.locationX){
            record.set('distance',Top5.app.getDistance(record.data.locationX,record.data.locationY,lat,lon).toFixed(3));
         }   
     }
}
更新:それで、私は自分の建物を出て、うまくいきました...もっと頻繁に外に出る必要があります。
ただし、gps を無効にすると、geoLocation は wifi 接続を使用して自分の場所を見つけると思っていましたが、失敗しました (enableHighAccuracy: false を設定しています)。何故ですか?
更新: 私の質問を言い換えさせてください: navigator.geolocation.watchPosition は、GPS 信号と wifi/g3 信号の両方で動作すると想定していますか? インターネット接続のみを使用してユーザーの位置を検出するにはどうすればよいですか? 現在、私のコードは GPS でのみ機能しており、そのオプションが無効になっているか、信号がブロックされている場合、地理位置情報は機能しません。