Jonathan Field
Jonathan Field

Reputation: 263

Phonegap/Cordova Geolocation Not working on Android 4.0+ but Working on all other platforms

I am using Phonegap version 3.30 with Phonegap build and UI elements provided by Sencha Touch. The app contains a map on the first page, the map is rendered using open street map and leaflet using a sencha touch library https://market.sencha.com/extensions/ext-ux-leafletmap .

If I set the map not to use the geolocation option which displays your location on the map then the map renders perfectly on all platforms, however when I enable the setting to use geolocation, the map renders perfectly and overlays the current location on all platforms (iOS, Android 2.0) but NOT Android 4.0+.

In fact on Android the map does not render at all which is similar behaviour to how it used to work with incorrect permissions. I have set the application to use the 3 location permissions via the Config.xml Phonegap geolocation plugin. Here is the link to the Config.xml https://www.dropbox.com/s/c1im3twg21mnxi6/config.xml

So to summarise: Android 4.0 only with Geolocation enabled prevents map from rendering, however the map and geolocation works on all other platforms.

Does anyone know what could be causing this? I have no errors being printed to the console and as far as I can the permissions are correct and as it works on Android 2.0 I am completely stumped.

Some pictures below demonstrating the issue, please note that Geolocation also works when the app is run on a web browser.

Android Not Loading with Geolocation Enabled Android Not Loading with Geolocation Enalbed

iOS Loading Correctly with Geolocation iOS Loading Correctly with Geolocation

Upvotes: 0

Views: 636

Answers (1)

Jonathan Field
Jonathan Field

Reputation: 263

I have solved the problem, this issue happens on Android 4.2, 4.3 and 4.4.

You have to explicitly enable the following options inside your call to Ext.util.geolocation. Allow High Accuracy and Frequency. This has been a massive headache @Sencha please make this simple.

var geo = Ext.create('Ext.util.Geolocation', {
        autoUpdate: false,
        allowHighAccuracy: true,
        frequency: '3000',
        listeners: {
            locationupdate: function(geo) {
                var currentLat = geo.getLatitude();
                var currentLng =  geo.getLongitude();
                var altitude = geo.getAltitude();
                var speed = geo.getSpeed();
                var heading= geo.getHeading();

// Ext.Msg.alert('Latitude Longitude' + currentLat + currentLng); }, locationerror: function(geo, bTimeout, bPermissionDenied, bLocationUnavailable, message) { if(bTimeout) { // Ext.Msg.alert('Timeout occurred',"Could not get current position"); } else { // alert('Error occurred.'); } } } }); geo.updateLocation();

Upvotes: 0

Related Questions