【问题标题】:When I start the App with GPS off , and later GPS is activated, Location is not detected当我在 GPS 关闭的情况下启动应用程序,后来 GPS 被激活时,未检测到位置
【发布时间】:2016-07-09 02:22:35
【问题描述】:

我在 Ionic App 中通过 Google 地图进行 GPS 检测时遇到问题。当我在关闭 GPS 的情况下启动应用程序,然后我从设置设备更改为打开 GPS,单击 Find Me 按钮 - centerOnMe() 功能 - GPS 无法正常工作。函数总是响应

`Error: GPS Timeout! ERROR = 3` 

一开始我以为是缓存问题,但我发现不是这样。从视图中使用 $state.reload 并不重要。 ¿ 有人遇到同样的问题吗?感谢您的支持。我附上下面的函数:

  $scope.centerOnMe = function() {

        $ionicPlatform.ready(function() {
        console.log('Click on Find Me');

        if(!map) {
            return;
        }

        $ionicLoading.show({
            content: 'Getting current location...',
            showBackdrop: false
        });

        //$state.reload('app.map');
        watchPositionId = navigator.geolocation.watchPosition(function(position) {                    
                navigator.geolocation.clearWatch(watchPositionId);
                var latitude     = position.coords.latitude;
                var longitude    = position.coords.longitude;
                $scope.latitude  = latitude;
                $scope.longitude = longitude;
                var geolocpoint  = new google.maps.LatLng(latitude, longitude);
                map.setCenter(geolocpoint);     
        });
        navigator.geolocation.getCurrentPosition(function (position) {
                   var lat  = position.coords.latitude
                   var long = position.coords.longitude                
                   $scope.center = new google.maps.LatLng(lat, long);
                   $ionicLoading.hide();
                   console.log("GPS is enabled" + $scope.center);
         }, function(err) {
                  // error
                  if (err.code == 1)     { console.log('GPS disabled! ERROR = '       + err.code);  }
                  else if(err.code == 2) { console.log('GPS is unavailable! ERROR = ' + err.code);  }
                  else if(err.code == 3) { console.log('Error: GPS Timeout! ERROR = ' + err.code);  }   
                  $ionicLoading.hide();
         }, {
                  enableHighAccuracy: true, timeout: 20000
            }  
         );

       });      
    };

【问题讨论】:

    标签: ionic-framework gps geolocation


    【解决方案1】:

    你最好使用this插件,

     cordova plugin add cordova.plugins.diagnostic
    

    会直接检测gps是否开启。

    有关更多详细信息,请查看以下 ionic 论坛问题,

    1. Geo location timeout vs location permission error
    2. Get Current Position not working after turning the GPS off on the device even if it turned on again?

    希望对你有帮助!!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-22
      • 2013-11-04
      相关资源
      最近更新 更多