如果您收听位置转换器
Ti.Geolocation.addEventListener('location',function(response){});
当位置改变和 GPS 开启或关闭时,你有一个事件
当你关闭你的 GPS 时,你的反应是
在安卓上:
{
"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状态
对于response.source.locationServicesEnabled中的android
如果response.error,则在iOS上检查状态或权限
if(response.error){
if(!Ti.Geolocation.locationServicesEnabled){
//GPS desactivate
}else if(Ti.Geolocation.hasLocationPermissions(Ti.Geolocation.AUTHORIZATION_ALWAYS) || Ti.Geolocation.hasLocationPermissions(Ti.Geolocation.AUTHORIZATION_WHEN_IN_USE)){
//no authorised
}
}
如果您想强制更改图标颜色,即使您没有位置事件,请在包含图标的窗口的 onFocus 事件中检查 GPS 状态和自动功能