地理围栏不会在前景中发生事件

时间:2015-05-06 14:23:12

标签: c# windows-runtime windows-phone windows-phone-8.1 geofencing

这是我第一次使用地理围栏开发应用程序。我有问题,当设备进入所需的竞技场时,地理围栏不会引发事件。我检查了msdn,一切都应该没问题。这是我的代码:

var _geolocator = new Geolocator();
BasicGeoposition pitchPosition;
pitchPosition.Latitude = 45.045213;
pitchPosition.Longitude = 19.040611;
pitchPosition.Altitude = 0.0;
double radius = 300;
Geocircle shape = new Geocircle(pitchPosition,radius);
MonitoredGeofenceStates monitoredGeofenceStates = MonitoredGeofenceStates.Entered;
TimeSpan timeToTrigger = TimeSpan.FromSeconds(1);
TimeSpan activeTimeSpan = TimeSpan.MaxValue;
DateTimeOffset startTime = DateTime.Now;
var _geofence = new Geofence(GeofenceId,shape,monitoredGeofenceStates,false,timeToTrigger,startTime,activeTimeSpan);   GeofenceMonitor.Current.GeofenceStateChanged += OnGeofenceStateChanged;

任何帮助将不胜感激:)

1 个答案:

答案 0 :(得分:0)

首先:您没有将地理围栏添加到监视器中:

GeofenceMonitor.Current.Geofences.Add(_geofence);

此外,您应该考虑更长的停留时间,以便事件有更多的时间进行处理。有时手机上的地理围栏监视器需要一些时间来学习(特别是在模拟器中)。

例如:如果您的地理围栏相当小并且您高速穿越它,那么您的活动可能根本不会发生。在开始时,尝试设置大栅栏并慢慢接近它们。地理围栏监视器将随着时间的推移适应您的运动配置文件。