PhoneGap Geolocation always gets timeout on special devices

I am using cordova 2.9.0 with PhoneGap Build. I wrote an application in which a user can register in a special place at a specific time. My problem is that when I install the application on various devices, I sometimes get a time schedule (this only happens on Android devices). When I restart the device, geolocation works, and I get GPS data. Now I would like to know if there is another way to solve this problem. My geolocation code in deviceReady function:

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 tried with different timeout values ​​and with HighAccuracy enabled, but nothing helps. Thanks.

+6
source share
2 answers

I also ran into this problem, mainly with Samsung android devices. I found out that:

  • If you do not have a SIM card installed in the device, then there will be no gps coordinates (which apply only to some devices).

  • Please make sure you have <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> installed in the Android manifest.

  • You should set enableHighAccuracy:true , please, below my settings:

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

enableHighAccuracy gives a hint that the application wants the best results. By default, the device will try to obtain a position using network methods. Setting this property to true indicates the use of more accurate methods, such as satellite positioning.

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

Hope this helps!

+4
source

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

I solved this by turning on the GPS "HighAccuracy" mode on the device (Android). (Settings β†’ Location access β†’ Mode).
The application user is prompted that he needs to enable this option in order to use the application ...

+1
source

Source: https://habr.com/ru/post/952589/


All Articles