rahuldas
rahuldas

Reputation: 120

Ext.util.Geolocation does not work in app in sencha touch

In my app a use Ext.util.Geolocation to fetch the current location in user. It is working in computer browser well as well as mobile browser. But when I create .apk file for android, then this class is not working.

the code is

getCurrentlocation: function () {
        var geo = new Ext.util.Geolocation({
            allowHighAccuracy : true,
            parseOptions: function() {
                var timeout = this.getTimeout(),
                    ret = {
                        maximumAge: this.getMaximumAge(),
                        enableHighAccuracy: this.getAllowHighAccuracy()
                    };

                if (timeout !== Infinity) {
                    ret.timeout = timeout;
                }
                return ret;
            },
            listeners : {
                locationupdate : function(geo) {
                    Ext.Msg.alert('Error', geo.getLatitude());
                    Proximity.app.currLat = geo.getLatitude();
                    Proximity.app.currLong = geo.getLongitude();
                    localStorage.setItem('currLat',geo.getLatitude());
                    localStorage.setItem('currLong',geo.getLongitude());
                },
                locationerror : function(geo, timeout) {
                    if (timeout){
                        console.log('Timeout occurred.');
                    } else {
                        console.log('Error occurred.');
                    }
                }
            }
        });
        geo.updateLocation();
     }

For this reason the I don't get the current location. If there is any supplementary way to get the coordinate, please tell me.

Thank You.

Upvotes: 0

Views: 1250

Answers (2)

Pavel K
Pavel K

Reputation: 55

Make sure, that you manifest file contains next string:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Upvotes: 0

n0daft
n0daft

Reputation: 125

I know there are several methods to locate a device using Sencha Touch:

  1. HTML5 Geolocation
  2. Ext.Util.Geolocation
  3. Ext.device.Geolocation

I never used Ext.util.Geolocation, however I made use of HTML5 Geolocation in my latest Sencha Touch project. To get the HTML5 Geolocation to work on the packaged apk and ios version I had to integrate the cordova Geolocation Plugin.

Official API Documentation http://cordova.apache.org/docs/en/2.5.0/cordova_geolocation_geolocation.md.html

GitHub Documentation https://github.com/apache/cordova-plugin-geolocation/blob/master/doc/index.md

After that I was able to get latitude and longitude with the following code snippet:

navigator.geolocation.getCurrentPosition( function(position){
              var lat = position.coords.latitude;
              var lng = position.coords.longitude;
        // HTML Geolocation error handling
        }, function(error){
              if (error.code == 1) {
                  // do something
              } else if (error.code == 2){
                  // do something
              } else if (error.code == 3){
                  // do something
              }
        }, 
        // Low Accuracy 
        {enableHighAccuracy: false},
        // Delivers new value after 75 seconds
        {maximumAge: 75000}
        ); // anonym function

And here is a great ducumentation about HTML5 Geolocation http://diveintohtml5.info/geolocation.html

Upvotes: 1

Related Questions