首页 文章

Cordova插件Geolocation不适用于Android版Kitkat

提问于
浏览
0

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

Install the plugin of cordova by command: cordova插件添加org.apache.cordova.geolocation

它在Android版本Jelly Bean(三星Galaxy Tab 2版本4.1.2 Jelly Bean,三星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)
           });
       }

1 回答

  • 0

    正如@laughingpine所说,这将有助于确切地知道您遇到的问题 .

    你说“它在Android版本Jelly Bean(三星Galaxy Tab 2版本4.1.2 Jelly Bean,三星Galaxy Grand 2版本4.1.2果冻 beans )中工作正常但位置关闭但在Android版本Kitkat(Samsung Note 2)中无效版本4.4.2 Kitkat) . “

    这意味着在Android 4.4.2上,当位置关闭时,错误回调没有被执行?或者,当位置服务打开时,正在执行错误回调而不是成功回调?如果是这样,请给我们错误输出 .

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

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

相关问题