如何获得用户位置,通过GPS在煎茶 [英] How to get user position by GPS in Sencha
问题描述
我试图让在煎茶触摸2用户的位置是:
I'm trying to get user position in Sencha Touch 2:
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功能。
But I've got coordinates only from network. There's no GPS icon on Android device, pointing that I'm using GPS. Also it doesn't work when I turn off internet connection. How can I enable GPS positioning? In Manifest file GPS is enabled.
推荐答案
我这个刚刚有点太。
原来有一个在煎茶中的错误:在的 Ext.util.Geolocation.parseOption 他们命名参数 allowHighAccuracy
不过的 命名的W3C规范 enableHighAccuracy
。
我增加了以下code到我的应用程序初始化来解决这个问题:
It turns out there's a bug in Sencha: in Ext.util.Geolocation.parseOption they name the parameter allowHighAccuracy
but the w3c specs name it enableHighAccuracy
.
I added the following code to my application init to fix that:
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);
有关记录:错误<一href="http://www.sencha.com/forum/showthread.php?130292-OPEN-TOUCH-137-enableHighAccuracy-allowHighAccuracy-in-GeoLocation"相对=nofollow>据报道在一年前和的修复程序适用于TOUCH-2804在最近的版本
。我不知道这意味着什么,但肯定不够的缺陷仍处于2.0
For the record: the bug has been reported over a year ago, and the fix was applied for TOUCH-2804 in a recent build
. I don't know what that means, but sure enough the bug is still in 2.0
编辑:用上述方法不能很好地工作无论是。该GPS图标会打开和关闭的EXTS反复使用的setInterval调用getCurrentPosition。这样做的原因在于,本机watchPosition方法的iOS5
正在打破。在我的Android应用程序的目标我最终抛弃分机:util.Geolocation和directely使用navigator.geolocation.watchPosition。之后,它的工作就像一个魅力。
using the approach mentioned above doesn't work well either. The GPS icon would turn on and off as Exts calls getCurrentPosition repeatedly using a setInterval. The reason for doing this is that The native watchPosition method is currently broken in iOS5
. In my Android targeted application I ended up ditching Ext:util.Geolocation and directely used navigator.geolocation.watchPosition. After that it worked like a charm.
这篇关于如何获得用户位置,通过GPS在煎茶的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!