【问题标题】:GPS icon is not activeGPS 图标未激活
【发布时间】:2023-12-13 11:06:01
【问题描述】:

我使用 lenovo android 4.4.2、samsung android 4.4.4、tablet samsung android 4.1.2 来测试我的应用程序

我也使用过cordova 地理定位插件($cordovaGeolocation)。但问题是 gps 图标仍然没有出现在状态栏中/处于活动状态。因此,它使我的应用程序位置不准确。为了确认,我打开了我的谷歌地图应用程序来查看 GPS 图标是否出现,结果是图标处于活动状态。

然后,我尝试在 iOS 中运行我的应用,出现了图标。

这是我的 javascript 代码:

    var options = {
        enableHighAccuracy: true,
        maximumAge: 0,
        timeout: 10000
    };

    $cordovaGeolocation.getCurrentPosition(options).then(function (pos) {
        latlong =  { 'lat' : pos.coords.latitude, 'long' : pos.coords.longitude };
        $rootScope.currentLocation = latlong;
    }, function(err) {});

我想知道为什么没有出现 gps 图标。如果是因为我的 android 版本或我的设备,但我已经使用 mauron85-background-geolocation 来运行后台。它确实出现了 gps 图标。

我已经对此问题进行了研究,但它也无法解决我的问题。 这里 -> https://forum.ionicframework.com/t/gps-icon-when-using-geolocation-is-not-active/22426/3

【问题讨论】:

    标签: javascript gps geolocation ionic-framework


    【解决方案1】:

    已经解决了问题。这是我的代码

    .controller('MapCtrl', function ($scope, $state, $cordovaGeolocation, $interval) {
    
    var options = {
        enableHighAccuracy: true,
        maximumAge: 3000,
        timeout: 30000
    };
    
    var watchOptions = {
        timeout: 3000,
        enableHighAccuracy: false
    };
    
    $cordovaGeolocation.getCurrentPosition(options).then(function (position) {
        var latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
    
        var mapOptions = {
            center: latLng,
            zoom: 15,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
    
        $scope.map = new google.maps.Map(document.getElementById("map"), mapOptions);
        google.maps.event.addListener($scope.map, 'idle', function () {
    
            var marker = new google.maps.Marker({
                map: $scope.map,
                position: latLng
            });
    
            marker.setMap($scope.map);
        });
    
        $interval(function () {
            $cordovaGeolocation.watchPosition(watchOptions).then(
                null,
                function (err) {
                    console.log(err);
                },
                function (position) {
                    var lat = position.coords.latitude;
                    var long = position.coords.longitude;
                    $scope.updateLoc = lat + " " + long;
                    $scope.digest();
                });
        }, 10000);
    
    
    }, function (error) {
        console.log("Could not get location");
    });
    

    });

    【讨论】: