【发布时间】:2015-02-12 13:42:40
【问题描述】:
我有一些代码允许我在 windows phone 8.1 中添加 GeoFences 并触发后台任务。在后台任务中,我想添加一个新的 GeoFence,但是在某些坐标上,这会导致 aghost.exe 退出并出现代码 1 错误。有没有办法在后台持续添加地理围栏,以免崩溃?
【问题讨论】:
标签: c# windows-phone-8.1 geofencing
我有一些代码允许我在 windows phone 8.1 中添加 GeoFences 并触发后台任务。在后台任务中,我想添加一个新的 GeoFence,但是在某些坐标上,这会导致 aghost.exe 退出并出现代码 1 错误。有没有办法在后台持续添加地理围栏,以免崩溃?
【问题讨论】:
标签: c# windows-phone-8.1 geofencing
应该没有问题。我使用地理围栏进行永久位置跟踪。这是我正在使用的一段代码。地理围栏对我有用(已知问题除外)。
public void AddGeoFence(Geopoint gp, String name, double radius)
{
// Always remove the old fence if there is any
var oldFence = GeofenceMonitor.Current.Geofences.Where(gf => gf.Id == name).FirstOrDefault();
if (oldFence != null)
GeofenceMonitor.Current.Geofences.Remove(oldFence);
Geocircle gc = new Geocircle(gp.Position, radius);
// Just listen for exit geofence
MonitoredGeofenceStates mask = 0;
mask |= MonitoredGeofenceStates.Exited;
// Construct and add the fence
Geofence newFence = new Geofence(new string(name.ToCharArray()), gc, mask, false, TimeSpan.FromSeconds(7), DateTimeOffset.Now, new TimeSpan(0));
GeofenceMonitor.Current.Geofences.Add(newFence);
}
【讨论】: