问题
I downloaded and installed the CrossGeofence plugin for xamarin here: https://github.com/domaven/xamarin-plugins/tree/master/Geofence
Used the sample found here as a guideline: https://github.com/domaven/xamarin-plugins/tree/master/Samples/Geofence
And I've been testing it out on my physical phone, the LGE LG-D852 (Android 6.0 - API 23) with usb debugging.
My CrossGeofenceListener class has been implemented such as:
public class CrossGeofenceListener : IGeofenceListener
{
//TODO: figure out what to do with this one.
public void OnAppStarted()
{
//throw new NotImplementedException();
}
//copied from geofence sample
public void OnError(string error)
{
Debug.WriteLine(string.Format("{0} - {1}: {2}", CrossGeofence.Id, "Error", error));
}
//TODO: figure out what needs to be done when the location changes.
public void OnLocationChanged(GeofenceLocation location)
{
//throw new NotImplementedException();
}
//copied from geofence sample
public void OnMonitoringStarted(string region)
{
Debug.WriteLine(string.Format("{0} - {1}: {2}", CrossGeofence.Id, "Monitoring in region", region));
}
//copied from geofence sample
public void OnMonitoringStopped()
{
Debug.WriteLine(string.Format("{0} - {1}", CrossGeofence.Id, "Monitoring stopped for all regions"));
}
//copied from geofence sample
public void OnMonitoringStopped(string identifier)
{
Debug.WriteLine(string.Format("{0} - {1}: {2}", CrossGeofence.Id, "Monitoring stopped in region", identifier));
}
//copied from geofence sample
public void OnRegionStateChanged(GeofenceResult result)
{
Debug.WriteLine(string.Format("{0} - {1}", CrossGeofence.Id, result.ToString()));
}
}
and I've created and started monitoring fences such as:
foreach (var facility in Facilities)
{
CrossGeofence.Current.StartMonitoring(new GeofenceCircularRegion(facility.Name, facility.Latitude, facility.Longitude, 2000)
{
NotifyOnStay = true,
NotifyOnEntry = true,
NotifyOnExit = true,
ShowNotification = true,
ShowEntryNotification = false,
ShowExitNotification = false,
ShowStayNotification = true,
NotificationStayMessage = "stay message!",
NotificationEntryMessage = "entry message!",
NotificationExitMessage = "exit message!",
StayedInThresholdDuration = TimeSpan.FromSeconds(1),
});
}
With the above given, I am only getting the entered geofence notification popping up. I'm not getting the exit and stayed transition notifications. Any suggestions on how to get the stayed and exit transitions to trigger?
回答1:
After spoofing the gps co-ordinates with another app it has started reporting the stay and exit notifications correctly. My only assumption is that nothing was working before due to the gps cordinates not changing drastically enough.
回答2:
Accordingly to the following snippet of code (described on your post):
ShowEntryNotification = false,
ShowExitNotification = false,
ShowStayNotification = true,
you should receive Stay notifications but no entry / exit, in order to receive the three of them set the proper Show...Notification to true.
来源:https://stackoverflow.com/questions/37162744/xamarin-crossgeofence-transitions