Appcelerator Titanium Tian Ti.Geolocation.addEventListener(';location';,{});关闭gps时不触发

Appcelerator Titanium Tian Ti.Geolocation.addEventListener(';location';,{});关闭gps时不触发,gps,titanium,appcelerator,Gps,Titanium,Appcelerator,无论何时在移动设备中打开或关闭gps,我都需要更改图标颜色。目前我正在使用Ti.Geolocation.addEventListener('location',{})用于在打开或关闭gps时触发。当我打开gps时它会触发,但当我关闭gps时它不会触发。我在android和iOS中都需要这项功能,但这两种系统都不起作用 为什么当我们离开gps时,这个api没有触发?任何其他方法都可以解决此问题。我认为他们没有这样的事件侦听器可以在GPS关闭时触发,相反,您可以尝试以下代码,看看它是否解决了您的问题

无论何时在移动设备中打开或关闭gps,我都需要更改图标颜色。目前我正在使用
Ti.Geolocation.addEventListener('location',{})用于在打开或关闭gps时触发。当我打开gps时它会触发,但当我关闭gps时它不会触发。我在android和iOS中都需要这项功能,但这两种系统都不起作用


为什么当我们离开gps时,这个api没有触发?任何其他方法都可以解决此问题。

我认为他们没有这样的事件侦听器可以在GPS关闭时触发,相反,您可以尝试以下代码,看看它是否解决了您的问题:

exports.testGPS = function(_callback) {
    Ti.Geolocation.purpose = "Recieve User Location";
    Ti.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST;
     if (_callback && typeof(_callback)==='function') {
        Ti.Geolocation.getCurrentPosition(function(e) {
                _callback ((e.error) ? false: true);
        });    
    }
}
您可以根据需要更新此功能。会的 获取时通过false,检索当前 设备的位置,因此我们可以得出结论,GPS 设置已关闭

祝你好运, 干杯

编辑 您可以使用广播接收器执行此操作,请参见以下内容:

更改tiapp.xml中的清单

<key>UIBackgroundModes</key>
<array>
     <string>location</string>
</array>

我认为没有这样的事件侦听器可以在GPS关闭时触发,相反,您可以尝试以下代码,看看它是否解决了您的问题:

exports.testGPS = function(_callback) {
    Ti.Geolocation.purpose = "Recieve User Location";
    Ti.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST;
     if (_callback && typeof(_callback)==='function') {
        Ti.Geolocation.getCurrentPosition(function(e) {
                _callback ((e.error) ? false: true);
        });    
    }
}
您可以根据需要更新此功能。会的 获取时通过false,检索当前 设备的位置,因此我们可以得出结论,GPS 设置已关闭

祝你好运, 干杯

编辑 您可以使用广播接收器执行此操作,请参见以下内容:

更改tiapp.xml中的清单

<key>UIBackgroundModes</key>
<array>
     <string>location</string>
</array>

如果你听位置变换器
Ti.Geolocation.addEventListener('location',函数(响应){})
当位置改变以及gps设置为打开或关闭时,会发生一个事件

当您关闭gps时,您会得到以下响应:

在Android上:

 {
  "type": "location",
  "source": {
    "bubbleParent": true,
    "hasCompass": true,
    "__propertiesDefined__": true,
    "preferredProvider": "gps",
    "Android": {
      "bubbleParent": true,
      "manualMode": false,
      "apiName": "Ti.Geolocation.Android"
    },
    "lastGeolocation": "{\"latitude\":36.4880079,\"longitude\":2.8170365,\"altitude\":0,\"accuracy\":42.5,\"heading\":0,\"speed\":0,\"timestamp\":1488278209059}",
    "_events": {
      "location": {}
    },
    "locationServicesEnabled": false,
    "accuracy": 1,
    "apiName": "Ti.Geolocation"
  },
  "bubbles": false,
  "success": true,
  "code": 0,
  "error": "network is disabled",
  "cancelBubble": false
}
在iOS上

{
  "bubbles": true,
  "type": "location",
  "source": {
    "preferredProvider": null
  },
  "success": false,
  "code": 1,
  "error": "location",
  "cancelBubble": false
}
iOS上的事件在应用程序恢复时触发,在我的情况下,当应用程序在后台时跟踪GPS,将其添加到tiapp.xml中

<key>UIBackgroundModes</key>
<array>
     <string>location</string>
</array>


如果您想强制更改图标颜色,即使您没有位置事件,请检查窗口的GPS状态和onFocus事件中的自动设置。如果您收听位置更改器,它将包含图标
Ti.Geolocation.addEventListener('location',函数(响应){})
当位置改变以及gps设置为打开或关闭时,会发生一个事件

当您关闭gps时,您会得到以下响应:

在Android上:

 {
  "type": "location",
  "source": {
    "bubbleParent": true,
    "hasCompass": true,
    "__propertiesDefined__": true,
    "preferredProvider": "gps",
    "Android": {
      "bubbleParent": true,
      "manualMode": false,
      "apiName": "Ti.Geolocation.Android"
    },
    "lastGeolocation": "{\"latitude\":36.4880079,\"longitude\":2.8170365,\"altitude\":0,\"accuracy\":42.5,\"heading\":0,\"speed\":0,\"timestamp\":1488278209059}",
    "_events": {
      "location": {}
    },
    "locationServicesEnabled": false,
    "accuracy": 1,
    "apiName": "Ti.Geolocation"
  },
  "bubbles": false,
  "success": true,
  "code": 0,
  "error": "network is disabled",
  "cancelBubble": false
}
在iOS上

{
  "bubbles": true,
  "type": "location",
  "source": {
    "preferredProvider": null
  },
  "success": false,
  "code": 1,
  "error": "location",
  "cancelBubble": false
}
iOS上的事件在应用程序恢复时触发,在我的情况下,当应用程序在后台时跟踪GPS,将其添加到tiapp.xml中

<key>UIBackgroundModes</key>
<array>
     <string>location</string>
</array>



如果您想强制更改图标颜色,即使您没有位置事件,也要在包含图标的窗口的onFocus事件中检查GPS状态和自动设置

Ti.Geolocation.addEventListener('location',function(response){});当我们关闭gps时,事件本身不会触发。当我们关闭gpsI RECCHECK时,请检查此事件是否触发,并完成我的回复。事件被触发你可能想在android上使用手动模式(例如)并设置一个minAge。如果我没有记错,当您在打开GPS时有一个缓存值时,它将不会调用
位置
事件,直到您的位置发生变化。当我打开GPS时,此事件会完美调用,但当我关闭GPS时,此事件不起作用。您正在测试什么平台,您使用的是TiSDK,我对TiSDK 5.5.1Ti.Geolocation.addEventListener('location',function(response){})有此响应;当我们关闭gps时,事件本身不会触发。当我们关闭gpsI RECCHECK时,请检查此事件是否触发,并完成我的回复。事件被触发你可能想在android上使用手动模式(例如)并设置一个minAge。如果我没有记错,当您在打开GPS时有一个缓存值时,它将不会调用
位置
事件,直到您的位置发生变化。当我打开GPS时,此事件会完美调用,但当我关闭GPS时,此事件不起作用。您正在测试什么平台,您使用的是TiSDK,我对TiSDK 5.5.1有此响应。为了使用此函数,我需要调用此函数,对吗?但我的问题是当我关掉gps时,我需要一个触发器。如何在每次我打开或关闭gps时触发。在这个函数中,我可以调用上面提到的函数。你对此有什么想法吗?@Dev786:嗨,我已经编辑了这些问题,我想这会满足你的要求。请看一看,让我知道它是否工作正常。不幸的是,它在android中不工作。我们是否需要在清单中添加任何用户权限。请确认这一点。我也需要在ios中工作。请提供在tiapp.xml中提到的用户权限。位置提供商的braodcast接收器不工作。您可以吗确认使用这个函数我需要调用这个函数,对吗?但我的问题是当我关掉gps时,我需要一个触发器。如何在每次我打开或关闭gps时触发。在这个函数中,我可以调用上面提到的函数。你对此有什么想法吗?@Dev786:嗨,我已经编辑了这些问题,我想这会满足你的要求。请看一看,让我知道它是否工作正常。不幸的是,它在android中不工作。我们是否需要在清单中添加任何用户权限。请确认这一点。我也需要在ios中工作。请提供在tiapp.xml中提到的用户权限。位置提供商的braodcast接收器不工作。您可以吗确认一下