You are here

navigator.geolocation not work in Android 4.1.2, soulution

One hybrid app with Phonegap 1.9.0 worked fine in Android 3.0 and 4.0, but when I update the OS to 4.1.2, the navigator.geolocation stop working.
Firstly i update the project with new version of phonegap cordova 2.7.0, it does not help. And I found even i test navigator.geolocation in Android native brower, under this demo link:

http://html5demos.com/geo
The gps operation was never be called. And i found many other developers have same problem in new Android OS.

At last I found one solution(not 100%, but at least works now):
My orginal code:

  1. navigator.geolocation.getCurrentPosition(onGeoLocateSuccess,
  2. onGeoLocateError,
  3. {
  4. enableHighAccuracy : false,
  5. maximumAge : 0,
  6. timeout : 7000
  7. });

-->change to:
  1. navigator.geolocation.getCurrentPosition(onGeoLocateSuccess,
  2. onGeoLocateError,
  3. {
  4. enableHighAccuracy : true,
  5. maximumAge : 3000,
  6. timeout : 60000
  7. });

make sure enableHighAccuracy is enabled. Why i called it is not 100% solution because in old version, if you are in one house without GPS signal, but you have wifi, you can still get your inaccurrate location depends on the wifi spot; but now, the inaccurate geolocation with wifi does not work anymore. That means you must have GPS signal to receive the real geolocation.

I dont know why Google turned this off in new OS, maybe privacy issue??

Ref:
http://community.phonegap.com/nitobi/topics/gelocation_in_phonegap_build_service_targetting_phonegap_2_3_hangs