2012-03-29 45 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