I use cordova 1.6.1 and try to access the gps. But onSuccess function never fires or onError either. GPS is on and the signal is there (tested with Maps at the same time). The code must be right because I used the same eventListener for the camera. The camera works perfectly with onSuccess/onError functions.
I run a Nexus S with Android 4.0.4 . BTW I tested the same code on an iPhone device & simulator and it works perfectly but not on Nexus S. Is there something wrong with Android implementation of phone gap? This is the part of the index.html:
<body>
<script type="text/javascript">
document.addEventListener("deviceready", onDeviceReady, false);
function onSuccess(position) {
alert("onSuccess");
$("#lat").html(position.coords.latitude);
$("#lon").html(position.coords.longitude);
}
function onError(error) {
alert("ERROR= " + error.message + "ERROR code= " +error.code );
}
function onDeviceReady() {
//navigator.camera.getPicture(onSuccess, onError, { quality: 20, destinationType: Camera.DestinationType.FILE_URI, encodingType: Camera.PictureSourceType.PHOTOLIBRARY });
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
</script>
<p id="lat"></p>
<p id="lon"></p>
</body>
I also tested the watchPosition function but it didn’t work either on Nexus S (also with enableHighAccuracy: true option and the other options but no success).
Thanks!
Edit1: The GPS symbol is also starting to blink and then appears after 1 minute or so, but still no onSussess!
Edit2: Here is the log from the device. It is something with permissions in the sql db but i have the all location permissions added to the AndroidManifest.xml . The —–REAAAAAAAAAADYYYYYYYYYY string comes from the onDeviceREady() function.
--------- beginning of /dev/log/system
W/InputManagerService( 135): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@4167b828
I/ActivityManager( 135): START {act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 cmp=com.android.launcher/com.android.launcher2.Launcher} from pid 135
--------- beginning of /dev/log/main
D/dalvikvm( 135): GC_FOR_ALLOC freed 512K, 10% free 14081K/15495K, paused 48ms
I/dalvikvm-heap( 135): Grow heap (frag case) to 13.950MB for 129616-byte allocation
D/dalvikvm( 135): GC_FOR_ALLOC freed 51K, 10% free 14156K/15623K, paused 47ms
W/InputManagerService( 135): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@417236b0 (uid=10014 pid=1302)
I/CheckinService( 297): Preparing to send checkin request
I/EventLogService( 297): Accumulating logs since 1335819200143
I/CheckinTask( 297): Sending checkin request (1952 bytes)
D/dalvikvm( 297): GC_CONCURRENT freed 418K, 6% free 10133K/10759K, paused 2ms+32ms
I/CheckinTask( 297): From server: 193 gservices
I/GservicesProvider( 297): main update completed
I/PersonalizationPrefManagerImpl( 1283): Google account found
I/PersonalizationPrefManagerImpl( 1283): Personalization disabled for SIM country code 262
I/SystemUpdateService( 297): cancelUpdate (empty URL)
D/dalvikvm( 297): GC_CONCURRENT freed 295K, 5% free 10240K/10759K, paused 2ms+3ms
I/ActivityManager( 135): START {flg=0x10040000 cmp=com.google.android.gsf/.update.SystemUpdateInstallDialog} from pid 297
W/ActivityManager( 135): Activity start request from 10019 stopped
D/dalvikvm( 1283): GC_CONCURRENT freed 308K, 5% free 9167K/9607K, paused 1ms+3ms
I/ActivityManager( 135): START {flg=0x10040000 cmp=com.google.android.gsf/.update.SystemUpdateDownloadDialog} from pid 297
W/ActivityManager( 135): Activity start request from 10019 stopped
V/SystemUpdateService( 297): onPostExecute: false
I/VoiceImeLanguageUpdater( 1283): #internalUpdateLanguages #56
I/ActivityManager( 135): START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.company.mobileApp/.DefaultActivity bnds=[0,556][120,706]} from pid 351
D/dalvikvm( 135): GC_FOR_ALLOC freed 367K, 11% free 14049K/15623K, paused 56ms
D/dalvikvm( 1335): Late-enabling CheckJNI
I/ActivityManager( 135): Start proc com.company.mobileApp for activity com.company.mobileApp/.DefaultActivity: pid=1335 uid=10015 gids={1006, 3003, 1015}
D/dalvikvm( 79): GC_EXPLICIT freed 37K, 4% free 9030K/9347K, paused 4ms+2ms
D/dalvikvm( 79): GC_EXPLICIT freed <1K, 4% free 9030K/9347K, paused 2ms+2ms
D/dalvikvm( 79): GC_EXPLICIT freed <1K, 4% free 9030K/9347K, paused 1ms+2ms
I/dalvikvm( 1335): Turning on JNI app bug workarounds for target SDK version 2...
D/OpenGLRenderer( 351): Flushing caches (mode 1)
D/OpenGLRenderer( 351): Flushing caches (mode 0)
D/dalvikvm( 351): GC_CONCURRENT freed 1344K, 30% free 11721K/16711K, paused 2ms+7ms
I/System.out( 1335): loadUrl(file:///android_asset/www/index.html,1000)
I/CheckinTask( 297): Checkin success: https://android.clients.google.com/checkin (1 requests sent)
D/dalvikvm( 1335): GC_FOR_ALLOC freed 85K, 3% free 9123K/9347K, paused 24ms
I/dalvikvm-heap( 1335): Grow heap (frag case) to 9.564MB for 614416-byte allocation
D/dalvikvm( 1335): GC_CONCURRENT freed 1K, 3% free 9722K/9991K, paused 5ms+2ms
V/PhoneStatusBar( 201): setLightsOn(true)
W/webcore ( 1335): java.lang.Throwable: EventHub.removeMessages(int what = 107) is not supported before the WebViewCore is set up.
W/webcore ( 1335): at android.webkit.WebViewCore$EventHub.removeMessages(WebViewCore.java:1683)
W/webcore ( 1335): at android.webkit.WebViewCore$EventHub.access$7900(WebViewCore.java:926)
W/webcore ( 1335): at android.webkit.WebViewCore.removeMessages(WebViewCore.java:1795)
W/webcore ( 1335): at android.webkit.WebView.sendOurVisibleRect(WebView.java:2917)
W/webcore ( 1335): at android.webkit.ZoomManager.setZoomScale(ZoomManager.java:593)
W/webcore ( 1335): at android.webkit.ZoomManager.access$1700(ZoomManager.java:49)
W/webcore ( 1335): at android.webkit.ZoomManager$PostScale.run(ZoomManager.java:984)
W/webcore ( 1335): at android.os.Handler.handleCallback(Handler.java:605)
W/webcore ( 1335): at android.os.Handler.dispatchMessage(Handler.java:92)
W/webcore ( 1335): at android.os.Looper.loop(Looper.java:137)
W/webcore ( 1335): at android.app.ActivityThread.main(ActivityThread.java:4424)
W/webcore ( 1335): at java.lang.reflect.Method.invokeNative(Native Method)
W/webcore ( 1335): at java.lang.reflect.Method.invoke(Method.java:511)
W/webcore ( 1335): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
W/webcore ( 1335): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
W/webcore ( 1335): at dalvik.system.NativeStart.main(Native Method)
I/ActivityManager( 135): Displayed com.company.mobileApp/.DefaultActivity: +1s484ms
I/System.out( 1335): loadUrl(file:///android_asset/www/index.html)
I/System.out( 1335): url=file:///android_asset/www/index.html baseUrl=file:///android_asset/www
D/dalvikvm( 1335): GC_CONCURRENT freed 120K, 3% free 10099K/10311K, paused 2ms+7ms
D/chromium( 1335): Unknown chromium error: -6
I/SqliteDatabaseCpp( 1335): sqlite returned: error code = 14, msg = cannot open file at line 27701 of [8609a15dfa], db=/data/data/com.company.mobileApp/databases/webview.db
I/SqliteDatabaseCpp( 1335): sqlite returned: error code = 14, msg = os_unix.c: open() at line 27701 - "" errno=2 path=/CachedGeoposition.db, db=/data/data/com.company.mobileApp/databases/webview.db
D/androidNetworkLocationListeners( 297): Still have listener com.google.android.location.internal.client.NetworkLocationClient$1@4137a068
D/androidNetworkLocationListeners( 297): Still have listener com.google.android.location.internal.client.NetworkLocationClient$1@4137a068
I/Web Console( 1335): -------------------------------REAAAAAAAAAADYYYYYYYYYY----------- at file:///android_asset/www/index.html:42
W/InputManagerService( 135): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@417419e8
D/dalvikvm( 1335): GC_CONCURRENT freed 640K, 8% free 9869K/10631K, paused 1ms+5ms
D/dalvikvm( 201): GC_FOR_ALLOC freed 143K, 28% free 10116K/13895K, paused 16ms
D/dalvikvm( 201): GC_FOR_ALLOC freed 364K, 28% free 10108K/13895K, paused 17ms
D/dalvikvm( 201): GC_CONCURRENT freed 318K, 27% free 10249K/13895K, paused 2ms+3ms
D/dalvikvm( 201): GC_CONCURRENT freed 501K, 27% free 10159K/13895K, paused 1ms+2ms
I/WifiLocationEstimator( 297): Not returning location for the following outliers: [127755693135544]
I/SqliteDatabaseCpp( 1335): sqlite returned: error code = 14, msg = cannot open file at line 27701 of [8609a15dfa], db=/data/data/com.company.mobileApp/databases/webview.db
I/SqliteDatabaseCpp( 1335): sqlite returned: error code = 14, msg = os_unix.c: open() at line 27701 - "" errno=2 path=/GeolocationPermissions.db, db=/data/data/com.company.mobileApp/databases/webview.db
D/dalvikvm( 297): GC_CONCURRENT freed 552K, 7% free 10143K/10823K, paused 2ms+4ms
I/ActivityManager( 135): START {act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 cmp=com.android.launcher/com.android.launcher2.Launcher} from pid 135
D/dalvikvm( 135): GC_FOR_ALLOC freed 397K, 9% free 14239K/15623K, paused 50ms
I/dalvikvm-heap( 135): Grow heap (frag case) to 14.104MB for 129616-byte allocation
D/dalvikvm( 135): GC_FOR_ALLOC freed 70K, 10% free 14295K/15751K, paused 48ms
W/InputManagerService( 135): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@4177e9d0 (uid=10015 pid=1335)
I/ActivityManager( 135): No longer want com.android.voicedialer (pid 1138): hidden #16
I/ActivityManager( 135): START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 pkg=org.jtb.alogcat cmp=org.jtb.alogcat/.LogActivity bnds=[120,556][240,706]} from pid 351
D/dalvikvm( 135): GC_FOR_ALLOC freed 185K, 10% free 14181K/15751K, paused 52ms
D/OpenGLRenderer( 351): Flushing caches (mode 1)
D/OpenGLRenderer( 351): Flushing caches (mode 0)
Ok. I packaged the app with phonegap build service and now it works. It was something wrong with packaging.