0

I can't get the Worklight "Location Services" "SmallSample" app to work on my Droid 4 phone. I am using the "smallSample" sample project provided by IBM Worklight.

The "SmallSample" app works great in the Mobile Browser Simulator, but when I install it on my physical phone.
When I press the button on the app to retrieve my GPS coordinates, the Android GPS icon appears for about 2 seconds in my notification bar, then disappears. The GPS coordinates are never displayed, and there are no errors.

Details:

  • I'm using Worklight Developer Edition 6.1.0.01
  • My phone is the Droid 4, Android 4.1.2 (API 16)
  • I imported the app to the Studio, then exported a signed APK using a new Keystore, and installed it on my phone.
  • I'm outside when using the app to ensure I can get GPS signal.
  • Other GPS apps work on my phone (Google maps).
  • I verified connectivity to my Worklight Server by opening the Worklight console with my mobile browser.
  • In the Worklight settings of the app, I verified the app is using the correct IP address, port, and context root to my Worklight Server.
  • I verified all the default permissions are there including:
<uses-permission android:name="android.permission.INTERNET"/>  
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>  
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>  
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>  
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

UPDATE:
Without changing anything else, I was able to retrieve GPS coordinates on my device a single point in time by using the code from this question: IBM Worklight - How to implement GPS functionality?

navigator.geolocation.getCurrentPosition(onSuccess, onError);

function onSuccess(position) {
  alert(JSON.stringify(position));
}

function onError(error) {
    alert(JSON.stringify(error));
}

The code above works perfectly on my phone and GPS coordinates are returned. However, the code from SmallSample (referenced in the link above) still doesn't work. One difference is the GPS coordinates are continually updated in Small Sample. I pasted the main part of the code below.

    WL.Device.Geo.acquirePosition(
        function(pos) {
            // when we receive the position, we display it and start on-going acquisition
            displayPosition(pos);


            var triggers = {
                Geo: {
                    posChange: { // display all movement
                        type: "PositionChange",
                        callback: function(deviceContext) {
                                displayPosition(deviceContext.Geo);
                            }
                    },

                    leftArea: { // alert when we have left the area
                        type: "Exit",
                        circle: {
                            longitude: pos.coords.longitude,
                            latitude: pos.coords.latitude,
                            radius: 200
                        },
                        callback: function() {
                            window.alert('Left the area');
                        }
                    },

                    dwellArea: { // alert when we have stayed in the vicinity for 3 seconds
                        type: "DwellInside",
                        circle: {
                            longitude: pos.coords.longitude,
                            latitude: pos.coords.latitude,
                            radius: 50
                        },
                        dwellingTime: 3000,
                        callback: function() {
                            window.alert('Still in the vicinity');
                        }
                    }
                }   
            };

            WL.Device.startAcquisition({ Geo: geoPolicy }, triggers, { Geo: alertOnGeoAcquisitionErr } );
        },
        function(geoErr) {
            alertOnGeoAcquisitionErr(geoErr);
            // try again:
            getFirstPositionAndTrack();
        },
        geoPolicy
    ); 

Also, here are the errors I get from LogCat(debug):

06-04 15:42:00.243: D/NONE(3962): wlclient init success

06-04 15:42:03.602: D/WL gps Listener: The location has been updated!

06-04 15:42:03.602: D/WL gps Listener: Acquired location age: 17306 milliseconds. More than maximumAge of 10000 milliseconds. Ignoring.

06-04 15:42:03.602: D/WL gps Listener: The status of the provider gps has changed

06-04 15:42:03.602: D/WL gps Listener: gps is TEMPORARILY_UNAVAILABLE

06-04 15:43:03.509: D/CordovaLog(3962): file:///android_asset/www/default/worklight/worklight.js: Line 12769 : Uncaught ReferenceError: PositionError is not defined

06-04 15:43:03.509: E/Web Console(3962): Uncaught ReferenceError: PositionError is not defined at file:///android_asset/www/default/worklight/worklight.js:12769

06-04 15:43:04.040: D/CordovaActivity(3962): Paused the application!

To summarize, the app gets my GPS coordinates initially, but then immediate throws "gps is TEMPORARILY_UNAVAILEABLE", and that process repeats. Perhaps my phone can't handle Live Tracking? Although live tracking works in Google maps on my device.

Community
  • 1
  • 1
  • Have you tested it in the Android emulator, to see if it works there? You can dynamically change the GPS coordinates there to ensure that it is working. That would help narrow it down to whether the problem is on the device or on Android. This question explains how to change the GPS coordinates in the emulator: http://stackoverflow.com/questions/2279647/how-to-emulate-gps-location-in-the-android-emulator – Daniel A. González Jun 02 '14 at 19:15
  • LogCat logs would help. – Idan Adar Jun 03 '14 at 17:54
  • Thanks Daniel. I verified the app does work in the Emulator, so the problem is when it runs on my Droid 4 physical device. Per Idan's suggestion, I will next investigate LogCat logs. – user3700295 Jun 04 '14 at 14:43
  • I'd like to verify that you are using the latest available version of Worklight - you can re-download the developer edition from the eclipse marketplace, and check whether the issue persists (delete the native folder and re-build afterwards). There was some issue around PositionError as seen above in the logs. – Idan Adar Jun 05 '14 at 03:26
  • I was using build: 6.1.0.01-20140427-1450 and then I upgraded to 6.1.0.01-20140518-1532. Unfortunately, since the 1532 upgrade, now the geolocation doesn't work in the Mobile Browser Simulator or Android Emulator any more. I think I'm just going to wait a few more days for 6.2 to be release. Thanks for your help! – user3700295 Jun 06 '14 at 21:16
  • @user3700295, 6.2 is released for some time now, did you try? – Idan Adar Sep 08 '14 at 17:29
  • @user3700295, by now 6.2.0.1 is also released for some time now. Did you try? – Idan Adar Nov 22 '14 at 14:35

1 Answers1

0

file:///android_asset/www/default/worklight/worklight.js: Line 12769 : Uncaught ReferenceError: PositionError is not defined

This issue was resolved in later versions of Worklight; my suggestion for you, if possible, is to upgrade your Studio installation to either the latest v6.2.0.01 release or even v6.3.

If you require it in v6.1, try upgrading to the latest iFix for 6.1.0.1 from IBM Fix Central.

Idan Adar
  • 44,156
  • 13
  • 50
  • 89