Phonegap/Cordova geolocation not working on Android

Posted by Kreeki on Stack Overflow See other posts from Stack Overflow or by Kreeki
Published on 2013-10-21T10:21:21Z Indexed on 2013/11/06 21:54 UTC
Read the original article Hit count: 326

Filed under:
|
|

I'm having a trouble to get Geolocation working on Android in both emulator (even when I geo fix over telnet) and on device. Works on iOS, WP8 and in the browser.

When I ask device for location using the following code, I always get an error (in my case custom Retrieving your position failed for unknown reason. with null both error code and error message).

Related code:

    successHandler = (position) ->
      resolve App.Location.create
        lat: position.coords.latitude
        lng: position.coords.longitude

    errorHandler = (error) ->
      error = switch error.code
        when 1
          App.LocationError.create
            message: 'You haven\'t shared your location.'
        when 2
          App.LocationError.create
            message: 'Couldn\'t detect your current location.'
        when 3
          App.LocationError.create
            message: 'Retrieving your position timeouted.'
        else
          App.LocationError.create
            message: 'Retrieving your position failed for unknown reason. Error code: ' + error.code + '. Error message: ' + error.message

      reject(error)

    options =
      maximumAge: Infinity # I also tried with 0
      timeout: 60000
      enableHighAccuracy: true
    navigator.geolocation.getCurrentPosition(successHandler, errorHandler, options)

platforms/android/AndroidManifest.xml

<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" />

www/config.xml (just in case)

<feature name="Geolocation">
    <param name="android-package" value="org.apache.cordova.GeoBroker" />
</feature>

Using Cordova 3.1.0. Testing on Android 4.2. Plugin installed. Cordova.js included in index.html (other plugins like InAppBrowser are working fine).

$ cordova plugins ls
[ 'org.apache.cordova.console',
'org.apache.cordova.device',
'org.apache.cordova.dialogs',
'org.apache.cordova.geolocation',
'org.apache.cordova.inappbrowser',
'org.apache.cordova.vibration' ]

I'm clueless. Am I missing something?

© Stack Overflow or respective owner

Related posts about android

Related posts about cordova