【问题标题】:How to track if location services is enabled or not enabled? titanium如何跟踪是否启用了位置服务?钛
【发布时间】:2014-08-19 16:52:30
【问题描述】:

我可以关掉它。

代码:

//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();
        }

    }
});

【问题讨论】:

    标签: ios geolocation titanium-mobile titanium-alloy


    【解决方案1】:

    更新:

    这成功了

    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】:
      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. 
      }
      

      【讨论】:

        猜你喜欢
        • 2012-04-28
        • 2021-03-07
        • 2014-08-22
        • 1970-01-01
        • 1970-01-01
        • 2016-04-24
        • 2011-11-05
        相关资源
        最近更新 更多