0

我在这里按照指南进行操作。

当一切都完成后(我创建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<-------
}
4

1 回答 1

1

您必须确保将Geofence您创建的内容添加到GeofenceMonitor.Current.Geofences集合中,以便监视器知道它。从文档中不是很清楚,但这是必须的。同样根据示例(示例将集合的引用存储在geofences字段中并使用它而不是GeofenceMonitor.Current.Geofences直接使用),如果监视器无法添加列表,建议将添加到列表的内容包装在异常处理程序中:

try
{
    GeofenceMonitor.Current.Geofences.Add( geofence );
}
catch
{
    //adding failed
}

我现在已经发送了一个拉取请求来更新文档以说明Geofence注册。

于 2018-02-13T07:54:51.143 回答