如何跟踪是否启用了位置服务?钛

时间:2014-06-28 21:29:26

标签: ios geolocation titanium-mobile titanium-alloy

我可以将其关闭。

代码:

//get current Location
//
Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST;
Titanium.Geolocation.distanceFilter = .25;

var overlays = require('overlays');
//check if gps is enabled
exports.checkGPS = function(windowCur) {
    Ti.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST;
    // make the API call
    var wrapperW = overlays.wrapperOverlay(windowCur);
    Ti.Geolocation.getCurrentPosition(function(e) {

        // do this stuff when you have a position, OR an error
        if (e.error) {
            Ti.API.error('geo - current position' + e.error);
            //put overlay on
            overlays.GPSError(windowCur);
            return;
        }else{

            //alert(JSON.stringify(windowCur));
            wrapperW.hide();        

        }

    });
};

这可以很好地确定用户是否已打开或关闭其位置服务。屏幕上会显示一个叠加层,告知用户如果已将其关闭,则需要将其打开。

然而问题是在用户设置之后,然后进入设置 - >定位服务并启用它,我无法关闭覆盖,因为我已经知道如果已经开启或关闭实时跟踪。

有人知道如何实现这一目标,欢呼。

更新:

这就是诀窍

var wrapperW = null;
Titanium.Geolocation.addEventListener('location', function(e) {
    if (e.error) {
        //put overlay on
        wrapperW = overlays.GPSError($.win);

    } else {

        //keep updating
        Ti.API.info(e.coords);
        if (wrapperW != null) {
            wrapperW.hide();
        }

    }
});

2 个答案:

答案 0 :(得分:0)

更新:

这就是诀窍

var wrapperW = null;
Titanium.Geolocation.addEventListener('location', function(e) {
    if (e.error) {
        //put overlay on
        wrapperW = overlays.GPSError($.win);

    } else {

        //keep updating
        Ti.API.info(e.coords);
        if (wrapperW != null) {
            wrapperW.hide();
        }

    }
});

答案 1 :(得分:0)

if (Titanium.Geolocation.locationServicesEnabled == false || Titanium.Geolocation.locationServicesAuthorization != Titanium.Geolocation.AUTHORIZATION_AUTHORIZED) {
    //'Location Services Disabled'
    // You need to check 2 conditions. first one for global location service another one is specific to your app. 
}