【问题标题】:How to get user position by GPS in Sencha如何在 Sencha 中通过 GPS 获取用户位置
【发布时间】:2012-03-29 12:27:24
【问题描述】:

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

【问题讨论】:

    标签: android sencha-touch


    【解决方案1】:

    我也只是被这个咬了。

    事实证明 Sencha 中有一个错误:在 Ext.util.Geolocation.parseOption 中,他们将参数命名为 allowHighAccuracy,但 the 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。我不知道那是什么意思,但果然bug还在2.0中

    编辑:使用上述方法也不能很好地工作。当 Exts 使用 setInterval 反复调用 getCurrentPosition 时,GPS 图标会打开和关闭。这样做的原因是The native watchPosition method is currently broken in iOS5。在我的 Android 目标应用程序中,我最终放弃了 Ext:util.Geolocation 并直接使用了 navigator.geolocation.watchPosition。之后,它就像一个魅力。

    【讨论】:

    • 是的,我也终于开始使用Phonegap的navigator.geolocation.watchPosition
    • 该错误已在 2.02 中修复 enableHighAccuracy 并可供支持订阅者使用,下一个公开版本是 2.1
    【解决方案2】:

    GPS 位置提供商使用卫星确定位置。根据条件,此提供程序可能需要一段时间才能返回位置修复。 需要权限 android.permission.ACCESS_FINE_LOCATION.

    【讨论】:

    【解决方案3】:

    嘿,我认为您需要更新的经度和纬度值。

    点击此链接..Click Here

    我已经尝试过了,并在安卓手机上测试过。它的工作原理。

    注意:必须并且应该在具有 GPS 状态的 android 手机中进行测试。它不会在eclipse模拟器上显示。但是会显示在手机上试试看..

    玩得开心。

    【讨论】:

    • 有趣的信息,但它也适用于纯 Java。我在 Sencha 框架中开发,我需要通过这个框架访问 GPS。在文档中,他们说 Ext.util.Geolocation 自动使用 GPS,但我无法做到。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多