在GPS /位置关闭之前,navigator.geolocation.getCurrentPosition始终在Android中超时 [英] navigator.geolocation.getCurrentPosition always getting timeout in Android until GPS/Location is OFF

查看:1233
本文介绍了在GPS /位置关闭之前,navigator.geolocation.getCurrentPosition始终在Android中超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  app.controller('dashboard',function($ scope){
$ scope.getPosition = function(position){
$ scope.acc = position .coords;
$ scope.lat = position.coords.latitude;
$ scope.lng = position.coords.longitude;
$ scope。$ apply();
} ;
$ scope.getPositionErr = function(error){
alert('code:'+ error.code +'\\\
'+
'message:'+ error.message +' \ n');
};
navigator.geolocation.getCurrentPosition($ scope.getPosition,$ scope.getPositionErr,{maximumAge:0,timeout:6000,enableHighAccuracy:false});
});

我使用Angular JS和Cordova作为Android应用程序。
此代码在桌面上运行正常,但不支持带有棒棒糖的Nexus 4。
另外控制器代码正在按照Cordova的要求在deviceready之后执行

我试过了


  • 将HighAccuracy设置为false

  • 删除地理位置插件,以便使用来自Wifi的默认位置
  • 设备重新启动

  • 清除浏览器缓存

  • 开启/关闭飞行模式

  • 无线开/关
  • >移动数据打开/关闭


但我无法获取纬度,长时间和地理位置总是超时。



只有在启用位置/ GPS设置时才有效。

解决方案

我有相同的问题,并为我解决了这个问题。

  {enableHighAccuracy:false,maximumAge:Infinity,timeout:60000} 


app.controller('dashboard', function($scope){
    $scope.getPosition = function(position){
        $scope.acc = position.coords;
        $scope.lat = position.coords.latitude;
        $scope.lng = position.coords.longitude;
        $scope.$apply();
    };
    $scope.getPositionErr = function(error){
        alert('code: '    + error.code    + '\n' +
                  'message: ' + error.message + '\n');
    };
    navigator.geolocation.getCurrentPosition($scope.getPosition, $scope.getPositionErr, {maximumAge: 0, timeout: 6000, enableHighAccuracy:false});
});

I am using Angular JS and Cordova for an Android app. This code is working fine on desktop but not on Nexus 4 with Lollipop. Also controller code is executing after deviceready as per requirement from Cordova

I have tried

  • Setting HighAccuracy to false
  • Removing geolocation plugin so that it uses default location from Wifi
  • Device reboot
  • Clearing browser cache
  • Airplane mode on/off
  • Wifi on/off
  • Mobile data on/off

But I am unable to get lat, long and geolocation always gets timeout.

It only works when I enabled Location/GPS from setting. After enabling it code is working as expected.

解决方案

I had identical issue and this fixed it for me

  {enableHighAccuracy:false,maximumAge:Infinity, timeout:60000}

这篇关于在GPS /位置关闭之前,navigator.geolocation.getCurrentPosition始终在Android中超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆