1

Worklight 6.2.0.00-20120814-0824

Location code runs fine in Browser simulator but fails in Android emulator, neither success nor failure callbacks firing.

Logcat shows:

10-06 16:00:40.707: W/PluginManager(3193): THREAD WARNING: exec() call to WLGeolocationPlugin.getLocation blocked the main thread for 75ms. Plugin should use CordovaInterface.getThreadPool().

code:

var showPosition = function(position) {
        WL.Logger.debug("got a position");
        var latitude = Number(position.coords.latitude).toFixed(2);
        var longitude = Number(position.coords.longitude).toFixed(2);
        $("#currentLocation").text(latitude + " / " + longitude);

    };

    var positionError = function(err) { 
        WL.Logger.debug("failed to get  a position");
        $("#status").text("position error" + err); 

    };

    var geoPolicy = WL.Device.Geo.Profiles.RoughTracking(); // other profiles tried, same result

    WL.Device.Geo.acquirePosition(showPosition, positionError, geoPolicy);

Android manifest has

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

Before I added those I had different error conditions, indicating permissions errors, so I think permissions are now correct.

-------edited to add more info ----

I have deployed to a real Android device but still get no callbacks fired. I do see these messages in LogCat, indicating that Worklight is doing something with gps, but not providing answers so far as my code is concerned

GC_FOR_ALLOC freed 738K, 11% free 10956K/12200K, paused 38ms, total 38ms
[ 10-07 15:30:21.656 13319:13340 D/com.worklight.androidgap.plugin.WLLocationListener ]
WLLocationListener.onLocationChanged in WLLocationListener.java:174 :: The location has been updated!
[ 10-07 15:30:21.661 13319:13340 D/com.worklight.androidgap.plugin.WLLocationListener ]
 WLLocationListener.win in WLLocationListener.java:100 :: Acquired location age: 178 milliseconds. More than maximumAge of 100 milliseconds. Ignoring.
[ 10-07 15:30:21.661 13319:13340 D/com.worklight.androidgap.plugin.WLLocationListener ]
WLLocationListener.onStatusChanged in WLLocationListener.java:156 :: The status of the provider gps has changed
[ 10-07 15:30:21.666 13319:13340 D/com.worklight.androidgap.plugin.WLLocationListener ]
WLLocationListener.onStatusChanged in WLLocationListener.java:162 :: gps is TEMPORARILY_UNAVAILABLE
[ 10-07 15:30:21.686   546:  549 D/dalvikvm ]
 GC_CONCURRENT freed 432K, 6% free 10266K/10920K, paused 1ms+1ms, total 15ms
[ 10-07 15:30:21.686   546:12382 D/dalvikvm ]
WAIT_FOR_CONCURRENT_GC blocked 9ms


 [ 10-07 15:55:05.761 13671:13695 D/com.worklight.androidgap.plugin.WLLocationListener ]
 WLLocationListener.win in WLLocationListener.java:100 :: Acquired location age: 170 milliseconds. More than maximumAge of 100 milliseconds. Ignoring.
 [ 10-07 15:55:05.791 13671:13695 D/dalvikvm ]
GC_FOR_ALLOC freed 530K, 9% free 10268K/11252K, paused 22ms, total 22ms
 [ 10-07 15:55:05.791 13671:13695 D/com.worklight.androidgap.plugin.WLLocationListener ]
 WLLocationListener.onStatusChanged in WLLocationListener.java:156 :: The status of the provider gps has changed
 [ 10-07 15:55:05.796 13671:13695 D/com.worklight.androidgap.plugin.WLLocationListener ]
 WLLocationListener.onStatusChanged in WLLocationListener.java:162 :: gps is TEMPORARILY_UNAVAILABLE
[ 10-07 15:55:06.366 13671:13695 D/NONE     ]
 navigator :: back pages/home.html
[ 10-07 15:55:08.406 13671:13695 D/NONE     ]
 navigator :: loadPage :: myProfile
[ 10-07 15:55:08.431 13671:13695 D/NONE     ]
 myProfile :: buildDepartmentList Art and Architecture,Billing And Accounts,Claims
[ 10-07 15:55:08.441 13671:13695 D/NONE     ]
 myProfile :: myProfileInit fetch acquire pos
[ 10-07 15:55:21.741   365:  568 D/libgps   ]
 proxy_gps_status_cb: called. status(4)
[ 10-07 15:55:21.741   365:  568 D/libgps   ]
 proxy_gps_status_cb: normal GPS icon mode.
[ 10-07 15:55:21.746   365:  568 I/libgps   ]
 disarming wakeLockTimer
[ 10-07 15:55:21.746   365:  568 I/libgps   ]
[proxy_gps_release_wakelock_cb][line = 653]: release_wakelock(0)
djna
  • 54,992
  • 14
  • 74
  • 117
  • I do not know much about how the location APIs work, but here are some comments and suggestions. First, the warning that you are getting about the main thread is irrelevant to your issue and you can ignore it. As it states, it means that the Cordova plugin took that long to stop executing in the main thread, and is there more as a suggestion from Cordova to avoid blocking the main thread unnecessarily, but it does not indicate a failure or error. However, it does mean that the plugin executed its code and is probably waiting for the callbacks after acquiring your location. (continued...) – Daniel A. González Oct 06 '14 at 18:23
  • Second, I am not sure if the Android emulator has Location enabled by default. You should make sure that in the settings, the location is properly set to allow the app to get the location. Second, refer to this question/answer (http://stackoverflow.com/a/2279827/2245921) to see how to set GPS coordinates in your emulator, and see if you are getting anything. If that doesn't work, you might want to post all the permissions you have in your manifest to make sure you are not missing any. – Daniel A. González Oct 06 '14 at 18:25
  • The items I show from my manifest are those documented as being required for these APIs. My failure callback does not seem to fire - I have trace statements there. – djna Oct 06 '14 at 21:37
  • What is the exact build number of your 6.2 installation? – Idan Adar Oct 07 '14 at 04:09
  • updated version in question – djna Oct 07 '14 at 06:30

1 Answers1

4

The answer seems to be that I need to specify a maximumAge option

  var geoPolicy = WL.Device.Geo.Profiles.RoughTracking(); // other profiles tried, same result

  geoPolicy.maximumAge = 5000;

  WL.Device.Geo.acquirePosition(showPosition, positionError, geoPolicy);

The logs (shown above) indicate than an answer was obtained but discarded on the basis of its age. Seems like I need to specify maximumAge greater than the time taken to obtain a position.

djna
  • 54,992
  • 14
  • 74
  • 117
  • I believe the default minimum internal value used for maximumAge is set to 100ms (as you can see in the logs). You seem to be getting ~170ms - 180ms, if you don't mind positions up to 5s old then 5000 is fine. Otherwise, you can try setting e.g. to 500 for upto 500ms old. – MotiNK Oct 08 '14 at 09:42
  • 1
    Agreed. The issue for me is that it's not at all obvious that maximumAge should apply to a one-off request for position. I can see that when fencing or other motion tracking is needed it makes sense, but to return no answer, no error for an initial request for "where am I?" does not fit my understanding of what maximumAge should do. – djna Oct 08 '14 at 10:03
  • I think that there is a subtle defect here; the issue is that the underlying hardware will often return old positions back, however this should be fixed to deal with it properly. – MotiNK Oct 14 '14 at 08:51