简体   繁体   中英

Cordova plugin Geolocation is not working for Android version Kitkat

I have used the cordova plugin geolocation: https://github.com/apache/cordova-plugin-geolocation

Install the plugin of cordova by command: cordova plugin add org.apache.cordova.geolocation

It is working fine in Android version Jelly Bean (Samsung Galaxy Tab 2 version 4.1.2 Jelly Bean, Samsung Galaxy Grand 2 version 4.1.2 Jelly Bean) with location off but is not working in Android version Kitkat (Samsung Note 2 version 4.4.2 Kitkat).

 navigator.geolocation.getCurrentPosition(geolocationSuccess, geolocationError);
       function geolocationSuccess(position) {
           var latlng = "Latitude :" + position.coords.latitude + ", Longitude :" + position.coords.longitude);
           $ionicPopup.alert({
               title: "User Current Location",
               subTitle: "Location",
               template: latlng
           });
       }

       function geolocationError(error) {
           $ionicPopup.alert({
                   title: "Pajhwok Location",
                   subTitle: "Error",
                   template: JSON.stringify(error)
           });
       }

As @laughingpine says, it would help to know exactly what the issue is you're encountering.

You said "It is working fine in Android version Jelly Bean (Samsung Galaxy Tab 2 version 4.1.2 Jelly Bean, Samsung Galaxy Grand 2 version 4.1.2 Jelly Bean) with location off but is not working in Android version Kitkat (Samsung Note 2 version 4.4.2 Kitkat)."

By this do you mean that on Android 4.4.2 the error callback is not being executed when location is off? Or that the error callback is being executed instead of success callback when location services is on? If so, please give us the error output.

If the latter, you can try explicitly setting maxAge and timeout, eg

navigator.geolocation.getCurrentPosition(geolocationSuccess, geolocationError, {maxAge: 30000, timeout: 60000});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM