钛地理定位跟踪无法正常工作

时间:2017-05-09 15:32:13

标签: android ios geolocation titanium appcelerator

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

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
...

但是如果我在背景上运行另一个导航应用程序(比如计划),那么事件会不断被触发,我有设备的标题和速度,好像我只是因为其他应用而得到了这些事件。

在android上同样的问题,事件未正确触发

使用ti SDK 5.1.2和5.5.1进行测试

1 个答案:

答案 0 :(得分: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
    },...
相关问题