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.