【问题标题】:Cordova plugin Geolocation is not working for Android version KitkatCordova 插件 Geolocation 不适用于 Android 版本 Kitkat
【发布时间】:2015-07-06 12:14:59
【问题描述】:

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

通过命令安装cordova的插件: cordova 插件添加 org.apache.cordova.geolocation

它在关闭位置的 Android 版本 Jelly Bean(Samsung 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)
           });
       }

【问题讨论】:

  • template: JSON.stringify(error) 想将该错误打印到控制台/复制并粘贴到这里?调试控制台中出现的任何其他问题(因为您使用的是 kitkat,所以您可以使用 chrome 开发工具!)
  • cordova 地理定位插件不再包含本机代码,所以如果它不起作用是 webview 的错,你无能为力
  • Cordova Geolocation 插件在 android 手机上打开位置的情况下工作正常。如果位置关闭,则在选项中设置超时后错误也会起作用

标签: android cordova geolocation cordova-plugins


【解决方案1】:

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

您说“它在关闭位置的 Android 版本 Jelly Bean(Samsung Galaxy Tab 2 版本 4.1.2 Jelly Bean、Samsung 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});

【讨论】:

  • 感谢您的回复。如果在 KitKat 移动设备上关闭位置,则不会执行错误和成功(仅在位置打开的情况下才有效)。但是在果冻豆上,它在位置关闭/打开的情况下工作..
  • 嘿@SubhashKumar,你解决了你的问题吗?我遇到了同样的问题。它正在其他 android 版本上工作,如 android 5+,但它在 kitkat 中给出超时错误。
  • 嗨@seyidyagmur,不,但我刚刚为应用程序添加了“需要位置权限”,它在除 KitKat 之外的所有版本中都能正常工作。如果用户在运行应用程序之前/期间设置位置/GPS - 关闭,那么我不会提供需要位置的选项/功能。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-26
  • 1970-01-01
  • 2021-12-24
相关资源
最近更新 更多