gpt4 book ai didi

android - Titanium 地理定位跟踪无法正常工作

转载 作者:行者123 更新时间:2023-11-29 11:45:58 36 4
gpt4 key购买 nike

我正在构建一个需要跟踪用户位置的应用程序,我使用

Ti.Geolocation.accuracy = Ti.Geolocation.ACCURACY_BEST;
Ti.Geolocation.distanceFilter = 0;
Ti.Geolocation.preferredProvider = Ti.Geolocation.PROVIDER_GPS
Ti.Geolocation.addEventListener('location', locationChange);

在 iOS 上,当设备在移动时,事件不会定期触发,当它被触发时,我没有航向和速度(甚至在驾驶时测试过)

...
heading : -1,
speed : -1
...

但如果我在后台运行另一个导航应用程序(如计划),该事件会不断触发,并且我有设备的航向和速度,就好像我只是因为其他应用程序而收到事件一样。

在安卓上同样的问题,事件没有被正确触发

使用 ti SDK 5.1.2 和 5.5.1 进行测试

最佳答案

这在过去曾让我绊倒过。添加
Ti.Geolocation.accuracy = Ti.Geolocation.ACCURACY_BEST_FOR_NAVIGATION;

另请注意,距离过滤器中的数字非常小可能会导致一些问题。

我用这个

if (OS_IOS) {
Ti.Geolocation.accuracy = Ti.Geolocation.ACCURACY_BEST_FOR_NAVIGATION;
Ti.Geolocation.distanceFilter = Alloy.CFG.minUpdateDistance;
Ti.Geolocation.preferredProvider = Ti.Geolocation.PROVIDER_GPS;
Ti.Geolocation.pauseLocationUpdateAutomatically = true;
Ti.Geolocation.activityType = Ti.Geolocation.ACTIVITYTYPE_OTHER_NAVIGATION;
} else { //Android
Ti.Geolocation.Android.manualMode = true;
var gpsProvider = Ti.Geolocation.Android.createLocationProvider({
name: Ti.Geolocation.PROVIDER_GPS,
minUpdateTime: Alloy.CFG.minAge / 1000,
minUpdateDistance: Alloy.CFG.minUpdateDistance
});

var gpsRule = Ti.Geolocation.Android.createLocationRule({
provider: Ti.Geolocation.PROVIDER_GPS,
accuracy: Alloy.CFG.accuracy,
maxAge: Alloy.CFG.maxAge,
minAge: Alloy.CFG.minAge,
});

Ti.Geolocation.Android.addLocationProvider(gpsProvider);
Ti.Geolocation.Android.addLocationRule(gpsRule);
Ti.Geolocation.Android.manualMode = true;
}

Alloy.CFG 设置在 config.json 文件中设置。

{ 
"global": {
"minUpdateDistance": 10,
"os:android": {
"accuracy": 20,
"minAge": 10000,
"maxAge": 30000
},...

关于android - Titanium 地理定位跟踪无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43874036/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com