我正在关注此处的指南。
所有完成(我创建Geofence
并将其放在地图上(时,如果输入Geofence
区域导航到它或在我的位置上创建它,什么也不会发生。
未调用OnGeofenceStateChanged
事件,因此我不知道如何管理Geofence
区域事件中的输入。
我做错了什么?
代码
private void DrawLOCNAME(double lat, double lon, string LOCNAME)
{
// Set the fence ID.
string fenceId = "LOCNAME";
// Define the fence location and radius.
BasicGeoposition position;
position.Latitude = lat;
position.Longitude = lon;
position.Altitude = 0.0;
// Set a circular region for the geofence.
Geocircle geocircle = new Geocircle(position, 2000);
// Set the monitored states.
MonitoredGeofenceStates monitoredStates =
MonitoredGeofenceStates.Entered |
MonitoredGeofenceStates.Exited |
MonitoredGeofenceStates.Removed;
// Set how long you need to be in geofence for the enter event to fire.
TimeSpan dwellTime = TimeSpan.FromSeconds(1);
//non so se è giusto ssettarlo a zero così
TimeSpan duration = TimeSpan.FromDays(1);
// Set up the start time of the geofence.
DateTimeOffset startTime = DateTime.Now;
// Create the geofence.
Geofence geofence = new Geofence(fenceId, geocircle, monitoredStates, false, dwellTime, startTime, duration);
// Register for state change events.
GeofenceMonitor.Current.GeofenceStateChanged += OnGeofenceStateChanged;
//GeofenceMonitor.Current.StatusChanged += OnGeofenceStatusChanged;
// Center the map over the POI.
Mappe.Center = snPoint;
//Mappe.ZoomLevel = 14;
}
public async void OnGeofenceStateChanged(GeofenceMonitor sender, object args)
{
var reports = sender.ReadReports();
//BLABLABLA IS NOT IMPORTANT
------->I'M NOT ABLE TO ENTER HERE<-------
}
您必须确保将创建的Geofence
添加到GeofenceMonitor.Current.Geofences
集合中,以便监视器知道它。从文档来看,这不是很清楚,但这是必须的。另外,根据样品(该示例将对集合的引用存储在geofences
字段中,并直接使用GeofenceMonitor.Current.Geofences
(,如果监视器未能添加它:
try
{
GeofenceMonitor.Current.Geofences.Add( geofence );
}
catch
{
//adding failed
}
我现在发送了一个拉动请求以更新文档以说明Geofence
注册。