Reputation: 169
I'm building an application on worklight 6.0 and I'm trying to implement geolocation.
The method WL.Device.Geo.acquirePosition
always returns
{"code":3,"message":"Position retrieval timed out."}
I followed these steps:
Placed this code in my javascript file:
function wlCommonInit() {
WL.Device.Geo.acquirePosition(positive, negative, {
timeout : 30000,
enableHighAccuracy: true,
maximumAge:15000
});
}
function positive(data) {
WL.Logger.debug("bbbbbbbbbbb2" + JSON.stringify(data));
}
function negativa(data) {
WL.Logger.debug("aaaaaaaaaaaa" + JSON.stringify(data));
}
add an android environment
add these two permissions in AndroidManifest.xml:
uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"
uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"
run the app on a samsung s2 with wifi and gps on
Is there anything that I'm missing?
Upvotes: 0
Views: 1242
Reputation: 1637
I faced this issue also and it was because I was using the WL API before mobile device Geo was ready.
In my case I copied the code from google maps examples code and it initializes everything with:
google.maps.event.addDomListener(window, 'load', initializeMap)
And then in initializeMap() method is where I tried to use the WL.Device.Geo.acquirePosition method.
You must call the initializeMap method in the wlCommonInit() method, not in a "windows load event listener", this way the call to WL.Device.Geo.acquirePosition() will be done when the device GEO is ready.
Also check in Android check in settings -> Location services that you have enabled Use wireless networks and I have had to enable also Location and Google search...
Upvotes: 0
Reputation: 11
See this post for more information.
Instead of doing:
navigator.geolocation.getCurrentPosition(win, fail, opts);
You can do this:
var geo = cordova.require('cordova/plugin/geolocation');
geo.getCurrentPosition(win, fail,opts);
Turns out you have to call the native module of Cordova to make this work without rebooting. You probably solved this or forgot, but may help other people.
Upvotes: 0
Reputation: 44516
I would also add to the AndroidManifest.xml the following:
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
And make sure this is there as well:
<uses-feature android:name="android.hardware.wifi" />
Did you try with a higher timeout value?
Upvotes: 1