PhoneGap的地理位置八方通上超时失败地理位置、PhoneGap

2023-09-05 03:02:40 作者:浊酒

我用我的应用程序煎茶触摸2.0和PhoneGap的2.0.0来获取用户的位置。 当我locahost乳宁,一切都运行得很好。然而,加载.apk文件到我的机器人15 API的设备时(使用Eclipse和ADT插件),每次调用getCurrentLocation或watchPosition不会返回...

I'm using sencha-touch 2.0 and phonegap 2.0.0 in my app to retrieve user's location. When runing on my locahost, everything works just fine. However, when loading the .apk to my android 15 api's device (using eclipse and the adt plugin), every call to getCurrentLocation or watchPosition never returns...

这是我的code:

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,我认为地理位置会使用wifi连接找到我的位置 - 但它failes(我设置enableHighAccuracy:假的)。这是为什么呢?

UPDATE: So i walked out of my building and it worked... i need to go outside more often. However, when I'm disabling the gps, I thought geoLocation will find my location using wifi connection - but it failes (i'm setting enableHighAccuracy: false). Why is that?

更新:没有人? O.K让我改一下我的问题: 难道navigator.geolocation.watchPosition假设与GPS信号和WiFi / G3信号工作两者兼而有之?如何检测用户位置只使用互联网连接?目前,我的code为只与全球定位系统,并在该选项禁用或信号被阻断,地理位置不工作.....请帮助!

UPDATE: No one? O.K let me rephrase my question: Does navigator.geolocation.watchPosition suppose to work both with GPS signal and wifi/g3 signals? How can I detect user location using internet connection only? currently, my code is working only with GPS, and when that option disabled or signal is blocked, geolocation isn't working..... HELP PLEASE!

推荐答案

我已经成功地解决它....但是,我不知道究竟解决了这个问题。所有我所做的是改变我的模型的结构之一。任何人都可以看到连接到地理定位的?

I've managed to work it out.... However , I have no idea what actually solved it. All I've done is to change one of my model's structure. Can anyone see the connection to geolocation?