Cordova插件Geolocation不支持Android版Kitkat

时间:2015-07-06 12:14:59

标签: android cordova geolocation cordova-plugins

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

通过命令安装cordova插件: 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 :(得分:0)

正如@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});
相关问题