I'm following the guide here.
And when all is done (I create the Geofence
and put it on the map), if I enter the Geofence
area navigating to it or creating it on my position nothing happens.
The OnGeofenceStateChanged
event is not called, and so I don't know how to manage the enter in Geofence
area event.
What do I do wrong?
Code
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<-------
}