Xamarin CrossGeofence 转换
Xamarin CrossGeofence Transitions
我在这里下载并安装了 xamarin 的 CrossGeofence 插件:https://github.com/domaven/xamarin-plugins/tree/master/Geofence
使用此处找到的样本作为指导:
https://github.com/domaven/xamarin-plugins/tree/master/Samples/Geofence
我一直在我的物理机 phone、LGE LG-D852(Android 6.0 - API 23)上进行 USB 调试测试。
我的 CrossGeofenceListener class 已实现,例如:
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()));
}
}
我已经创建并开始监控围栏,例如:
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),
});
}
根据以上给出的内容,我只会弹出输入的地理围栏通知。我没有收到退出和停留的过渡通知。关于如何触发停留和退出转换的任何建议?
在用另一个应用欺骗 gps 坐标后,它开始正确报告停留和退出通知。我唯一的假设是,由于 gps 坐标变化不够大,之前没有任何工作。
根据以下代码片段(在您的 post 中描述):
ShowEntryNotification = false,
ShowExitNotification = false,
ShowStayNotification = true,
您应该会收到 Stay 通知,但不会收到进入/退出通知,为了收到这三个通知,请将正确的 Show...Notification 设置为 true。
我在这里下载并安装了 xamarin 的 CrossGeofence 插件:https://github.com/domaven/xamarin-plugins/tree/master/Geofence
使用此处找到的样本作为指导: https://github.com/domaven/xamarin-plugins/tree/master/Samples/Geofence
我一直在我的物理机 phone、LGE LG-D852(Android 6.0 - API 23)上进行 USB 调试测试。
我的 CrossGeofenceListener class 已实现,例如:
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()));
}
}
我已经创建并开始监控围栏,例如:
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),
});
}
根据以上给出的内容,我只会弹出输入的地理围栏通知。我没有收到退出和停留的过渡通知。关于如何触发停留和退出转换的任何建议?
在用另一个应用欺骗 gps 坐标后,它开始正确报告停留和退出通知。我唯一的假设是,由于 gps 坐标变化不够大,之前没有任何工作。
根据以下代码片段(在您的 post 中描述):
ShowEntryNotification = false,
ShowExitNotification = false,
ShowStayNotification = true,
您应该会收到 Stay 通知,但不会收到进入/退出通知,为了收到这三个通知,请将正确的 Show...Notification 设置为 true。