【问题标题】:Geolocation.latLng() not working in androidGeolocation.latLng()在android中不起作用
【发布时间】:2016-03-31 18:54:28
【问题描述】:

我正在使用 mdg:geolocation 包,我正在尝试在 android 设备中运行它,但我不再了解 lat 和 lang,当我在几个月前尝试时它工作正常

我正在使用该软件包的 1.0.3* 版本

chrom 超出警告,将我带到page

因为这是一个警告,它应该起作用。

我什至尝试通过提供--mobile-server=https://myapp.com 来运行该应用程序,但它仍然无法正常工作。

有什么想法吗?

我的版本 流星 - 1.1.*(不是最新的) 地理位置 - 1.0.3

编辑

我尝试使用如下导航器对象

var onSuccess = function(position) {
   console.log('Latitude: '          + position.coords.latitude          + '\n' +
  'Longitude: '         + position.coords.longitude         + '\n' +
  'Altitude: '          + position.coords.altitude          + '\n' +
  'Accuracy: '          + position.coords.accuracy          + '\n' +
  'Altitude Accuracy: ' + position.coords.altitudeAccuracy  + '\n' +
  'Heading: '           + position.coords.heading           + '\n' +
  'Speed: '             + position.coords.speed             + '\n' +
  'Timestamp: '         + position.timestamp                + '\n');
};

// onError Callback receives a PositionError object
//
function onError(error) {
  console.log('code: '    + error.code    + '\n' +
  'message: ' + error.message + '\n');
}

navigator.geolocation.getCurrentPosition(onSuccess, onError);

我没有在控制台中获得任何日志,没有调用错误或成功回调

编辑 2

在 android mobile 上运行我的应用程序时这不起作用,如果我在 web 上运行相同的应用程序,我会得到 lat 和 lang 值。

编辑 3

我用--server 指向https://myapp.com 构建apk 仍然无法正常工作。

编辑 4

我还有一个最新版本的项目,尝试了上述所有步骤仍然无法正常工作(即使是构建 apk 版本)

编辑 5

在尝试@Adam 的建议后,我收到以下错误

code: 3 message: Timeout expired

尝试了 timeoutenablehighaccuracymaxage 的不同选项,但没有任何效果。

【问题讨论】:

  • atmoshere 是否使用外部网址?然后你应该把它加入白名单,阅读这个文档:cordova.apache.org/docs/en/dev/guide/appdev/whitelist/…
  • @Joerg 我通过meteor<access origin="*" /> 这个设置,我强烈认为问题是流星将它的起源设置为meteor.local 而不是localhost,所以根据新的chrome 更新,它将允许httpslocalhost,但这里是meteor.local
  • 您的index.html 中是否有内容安全策略?
  • 我的移动配置文件中有App.accessRule('*');这个

标签: cordova meteor


【解决方案1】:

使用 Android 模拟器,您可能必须先提供一个位置。所以,运行类似:

~/.meteor/android_bundle/android-sdk/platform-tools/adb emu geo fix <longitude value> <latitude value>

【讨论】:

  • 我用的是真机而不是模拟器
  • 啊,要运行错误代码,您必须为其设置超时。据我了解,它的默认值是无穷大。试试:navigator.geolocation.getCurrentPosition(success,error,{timeout:5000})。希望这会有所帮助;祝你好运。
  • 这确实有帮助,但我收到错误代码:3 timeout expired error
  • GPS 在每个设备上也往往有点奇怪。在某些情况下,关闭 WiFi、重启手机和清除缓存等简单的操作对我有帮助。
【解决方案2】:

你坚持你的问题吗?我可以使用

使其工作
var geo_err = Geolocation.error();
if(geo_err != null) alert(geo_err.message);
var pos = Geolocation.latLng();
if(pos == null) return false;

你需要把它放在一个帮助器中,因为它需要遍历它等待响应,否则总是会出错。 我使用一个按钮来更改 Session 变量的状态,该变量稍后会激活帮助程序,因此可以多次调用它。 希望有所帮助,我在 Android 和 chrome 中进行了测试,并且可以正常工作。 唯一的问题是我不能让用户请求许可,如果 gps 没有激活它会给我

超时错误 所以...期待。

【讨论】:

    猜你喜欢
    • 2018-06-18
    • 2021-08-31
    • 2016-02-20
    • 2015-05-25
    • 2011-09-19
    • 2012-12-26
    • 2017-02-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多