Search code examples
androidgpswifiibm-mobilefirstworklight-geolocation

IBM Worklight 6.0 - WL.Device.Geo.acquirePosition always return timeout


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:

  1. Created a new worklight project
  2. 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));
    }
    
  3. add an android environment

  4. 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"

  5. run the app on a samsung s2 with wifi and gps on

Is there anything that I'm missing?


Solution

  • 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?