gpt4 book ai didi

android - Sencha中如何通过GPS获取用户位置

转载 作者:太空狗 更新时间:2023-10-29 14:28:04 25 4
gpt4 key购买 nike

我正在尝试获取 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 定位?在 list 文件中启用了 GPS。

最佳答案

我也被这个咬到了。

事实证明 Sencha 中存在一个错误:在 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);

备案:bug has been reported over a year ago ,并且 在最近的构建中为 TOUCH-2804 应用了修复。我不知道那是什么意思,但可以肯定的是,该错误仍在 2.0 中

编辑:使用上述方法也效果不佳。当 Exts 使用 setInterval 重复调用 getCurrentPosition 时,GPS 图标会打开和关闭。这样做的原因是 原生的 watchPosition 方法目前在 iOS5 中被破坏。在我的 Android 目标应用程序中,我最终放弃了 Ext:util.Geolocation 并直接使用了 navigator.geolocation.watchPosition。在那之后,它就像一个魅力。

关于android - Sencha中如何通过GPS获取用户位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9925289/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com