user2001445
user2001445

Reputation:

PhoneGap Geolocation get always a timeout on special devices

I use cordova 2.9.0 with PhoneGap Build. I have written an app where a user can check-in on special location to a special time. My problem is that when I install de app on various devices I sometimes get always a timout (this occurs only on Android devices). When I restart the device the geolocation works and I get the gps-data. Now I'd like to know if there is another way to resolve this problem. My code for geolocation in the deviceReady function is:

var geo = cordova.require('cordova/plugin/geolocation');
var optionsGeo = {maximumAge: 0, timeout: 30000, enableHighAccuracy: false};
var watchID = geo.watchPosition(onSuccessGeo, errorGeo, optionsGeo);

function onSuccessGeo(position) {
  lat = (position.coords.latitude).toFixed(6);
  lon = (position.coords.longitude).toFixed(6);
  accuracy = (position.coords.accuracy).toFixed(0); 
  console.log("Lat " + lat + " Lon " + lon + " & " + accuracy + "m");
}

function errorGeo(error) {
  console.log("Geo-Fehler! Code: " + error.code + " Nachricht: " + error.message);
}

I have tried with different timeoutvalues and with enabled HighAccuracy - but nothing helps. Thanks.

Upvotes: 6

Views: 4061

Answers (2)

baam
baam

Reputation: 1162

I know this question is old but I encountered the same problem today using Cordova 3.5.0 with the geolocation plugin (org.apache.cordova.geolocation 0.3.8).

I solved it by enabling the GPS "HighAccuracy"-mode on the device (android). (Settings -> Location access -> Mode).
The app-user gets a hint that he needs to enable this option in order to use the app...

Upvotes: 1

George Artemiou
George Artemiou

Reputation: 3166

I was also facing this issue, mainly with Samsung android devices. What I found out is that:

  1. If you do not have a SIM card installed in the device, then there will be no gps coordinates (that's only applicable to some devices).

  2. Please make sure that you have <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> set in your android manifest.

  3. You should set enableHighAccuracy:true please see below my settings:

    var options = {maximumAge: 0, timeout: 10000, enableHighAccuracy:true}; navigator.geolocation.getCurrentPosition(onSuccess, onError, options);

enableHighAccuracy provides a hint that the application would like to receive the best possible results. By default, the device will attempt to retrieve a Position using network-based methods. Setting this property to true tells the framework to use more accurate methods, such as satellite positioning.

In some cases, developers use geolocation.watchPosition to get more accurate gps results. Can you also try that?

I hope it helps!

Upvotes: 4

Related Questions