Icenium phonegap geolocation not accurate

4 posts, 0 answers
  1. Jeremy
    Jeremy avatar
    4 posts
    Member since:
    Sep 2011

    Posted 27 Feb 2014 Link to this post

    Hi Team,

    I am working with icenium mobile app for Android and as per my requirement I need to run code to get accurate location from device. So I have used below code.

    navigator.geolocation.watchPosition(onSuccess, onError, { maximumAge: 3000, timeout: 5000, enableHighAccuracy: true });

    Below are the permission we have applied.

    <uses-permission android:name="android.permission.INTERNET" />
      <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" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />

    But when I am setting true enableHighAccuracy: true application not working and always give error about location not found, even I have run the sample application from telerik that is also not working. I have set all permission but still that is not working.

    If I am setting enableHighAccuracy: false thing is working but in this case location is not accurate, also in case of false if I am using wifi then location are almost accurate. 

    So can you please suggest what setting required for enableHighAccuracy: true. 

    Thanks,
    Amit Patel
  2. Iva Koevska
    Admin
    Iva Koevska avatar
    286 posts

    Posted 03 Mar 2014 Link to this post

    Hi Jeremy,

    Please, find the reply to your inquiry in your relevant support ticket. The support team will contain the discussion within the support ticket since this will minimize the maintenance and tracking effort.

    However, as soon as a solution to your problem becomes available, we will repost the information so that other users can benefit from your experience.

    Thank you for your understanding!

    Regards,
    Iva Koevska
    Telerik
    Icenium is now Telerik AppBuilder, and is part of the Telerik Platform. For more information on the new name, and to learn more about the Platform, register for the free online keynote and webinar on Wednesday, February 12, 2014 at 11:00 a.m. ET (8:00 a.m. PT)
  3. JET
    JET avatar
    19 posts
    Member since:
    Dec 2012

    Posted 03 Mar 2014 in reply to Iva Koevska Link to this post

    I am having the same issue as Jeremy. Please, advise on what to do as far as making the GeoLocation plugin work with Android devices. I am using Phonegap 3.2.0 and a Google Nexus 5 and get timeouts with high accuracy. It works perfectly on iOS devices.
  4. Iva Koevska
    Admin
    Iva Koevska avatar
    286 posts

    Posted 06 Mar 2014 Link to this post

    Hello Jetmyr,

    We have suggested a workaround and a detailed implementation of the workaround to Amit. You can find the explanation quoted below. Hope this helps!

    The culprit

    I can suggest you remove the geolocation plugin (from Project Properties) for Android devices that implement the geolocation in their default browser. When using this workaround you should add the following permissions to your AndroidManifest.xml:

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

    Have in mind that Cordova are removing their plugin code to allow the default browser implementation to surface. For more information regarding this, please take a look at this jira bug.

    To support older Android devices, that do not provide geolocation implementation in their WebView component, you would have to slightly modify and replace our Cordova geolocation plugin (the source code is located here). To replace it please disable your geolocation plugin from Project Properties and add the modified one as a Custom Plugin.

    Cordova have hardcoded 60000ms for refresh in the following places:

    https://github.com/apache/cordova-plugin-geolocation/blob/d11e00592b9e43baa7322c9d3f25d53b68ab2151/src/android/GPSListener.java#L44
    https://github.com/apache/cordova-plugin-geolocation/blob/d11e00592b9e43baa7322c9d3f25d53b68ab2151/src/android/CordovaLocationListener.java#L201

    Change them to something like 5000 and it will work as expected. Please take a look at the official Android documentation for choosing the minTime for loctionUpdates:

    Choosing a sensible value for minTime is important to conserve battery life. Each location update requires power from GPS, WIFI, Cell and other radios. Select a minTime value as high as possible while still providing a reasonable user experience. If your application is not in the foreground and showing location to the user then your application should avoid using an active provider (such as NETWORK_PROVIDER or GPS_PROVIDER), but if you insist then select a minTime of 5 * 60 * 1000 (5 minutes) or greater. If your application is in the foreground and showing location to the user then it is appropriate to select a faster update interval.

    The solution in detail

    I managed to replace the core Geolocation plugin with the one my colleague has referenced in his post. Here is the exact workflow I followed in order to do this:

    1.     First, I created a new blank project in AppBuilder;

    2.     Then, inside its project properties I disabled the core Geolocation plugin;

    3.     I downloaded the ZIP from here;

    4.     And added it under the Plugins folder of my project. This is achieved by right clicking on the Plugins folder and then selecting Add > From Archive;

    5.     Next, I had to change the minTime values for android devices in the sources of the already imported Geolaction plugin. This is needed on two places:

    o    Inside /src/android/GPSListener.java on line 44 you should find this:

    this.locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000, 0, this);

    Replace the 60000 value to 5000 for example.

    o    Inside /src/android/CordovaLocationListener.java on line 201 you should find this:

    this.locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 60000, 10, this);

    Again, replace the 60000 value with the same as above (5000 as in my case).

    6.     Note, you can do this directly in AppBuilder!

    7.     In order to test, if the plugin initializes I added the following lines in Index.html:

    if(navigator.geolocation == 'undefined') {

        alert("Geolocation not initialized!!!");

    } else {

        alert("Geolocation initialized!!!");

    }

    8.     I also added the code from your screenshot:

    var argscheck = require('cordova/argscheck'),

        utils = require('cordova/utils'),

        exec = require('cordova/exec');

     

    9.     Finally, I built the app and deployed it on android device. Everything worked as expected on HTC One device.


    Regards,
    Iva Koevska
    Telerik
    Icenium is now Telerik AppBuilder, and is part of the Telerik Platform. For more information on the new name, and to learn more about the Platform, register for the free online keynote and webinar on Wednesday, February 12, 2014 at 11:00 a.m. ET (8:00 a.m. PT)
Back to Top