How to get user position by GPS in Sencha

人盡茶涼 提交于 2020-01-13 05:27:27

问题


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   
            }
        }
    });

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.


回答1:


I just got bit by this too.

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);

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

EDIT: 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.




回答2:


GPS location provider determines location using satellites. Depending on conditions, this provider may take a while to return a location fix. Requires the permission android.permission.ACCESS_FINE_LOCATION.




回答3:


Hey I think you need updated longitude and latitude values .

follow this link.. Click Here

I already tried it and test it in android mobile phone.. Its working.

Note : Must and should test in android mobile phone with on GPS status. It will not show on eclipse emulator. But it will show in mobile phone try it..

have a nice.



来源:https://stackoverflow.com/questions/9925289/how-to-get-user-position-by-gps-in-sencha

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!