繁体   English   中英

Cordova插件Geolocation不适用于Android版本Kitkat

[英]Cordova plugin Geolocation is not working for Android version Kitkat

我已经使用了cordova插件地理位置: https : //github.com/apache/cordova-plugin-geolocation

通过命令安装 cordova插件 cordova plugin add org.apache.cordova.geolocation

在关闭位置的Android版本Jelly Bean(三星Galaxy Tab 2版本4.1.2 Jelly Bean,Samsung Galaxy Grand 2版本4.1.2 Jelly Bean)中运行正常,但在Android版本Kitkat(Samsung Note 2版本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)
           });
       }

正如@laughingpine所说,这将有助于准确了解您遇到的问题。

您说:“在关闭位置的情况下,它在Android版本Jelly Bean(三星Galaxy Tab 2 4.1.2 Jelly Bean,三星Galaxy Grand 2版本4.1.2 Jelly Bean)中工作正常,但在Android版本Kitkat(三星Note 2)中不起作用版本4.4.2 Kitkat)。”

您的意思是说在Android 4.4.2上,关闭位置后不会执行错误回调吗? 还是在开启位置服务时执行错误回调而不是成功回调? 如果是这样,请给我们错误输出。

如果是后者,则可以尝试显式设置maxAge和timeout,例如

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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