如何在 WP8.1 后台任务中添加新的 GeoFence?
How do I add a new GeoFence in a WP8.1 background task?
我有一些代码可以让我在 windows phone 8.1 中添加地理围栏并触发后台任务。在后台任务中,我想添加一个新的 GeoFence,但是在某些坐标上这会导致 aghost.exe has exited with code 1 错误。有没有办法在后台始终如一地添加地理围栏,以免崩溃?
应该没有问题。我使用地理围栏进行永久位置跟踪。这是我正在使用的一段代码。地理围栏对我有用(已知问题除外)。
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);
}
我有一些代码可以让我在 windows phone 8.1 中添加地理围栏并触发后台任务。在后台任务中,我想添加一个新的 GeoFence,但是在某些坐标上这会导致 aghost.exe has exited with code 1 错误。有没有办法在后台始终如一地添加地理围栏,以免崩溃?
应该没有问题。我使用地理围栏进行永久位置跟踪。这是我正在使用的一段代码。地理围栏对我有用(已知问题除外)。
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);
}