Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#UWP,在geofencemonitor中重用geofences_C#_Win Universal App_Geofencing - Fatal编程技术网

C#UWP,在geofencemonitor中重用geofences

C#UWP,在geofencemonitor中重用geofences,c#,win-universal-app,geofencing,C#,Win Universal App,Geofencing,我正在开发UWP应用程序,它将帮助我所在城市的人们使用公共交通工具。当设备靠近某个站点时,它使用地理围栏进行通知。一切正常,但进展缓慢。在我的Lumia830上,为所有250个地理围栏准备数据并创建它们需要4-5秒。由于geofencemonitor在系统下运行,即使在我的应用程序终止时也可以存储我的geofences,所以我认为最好不要在每次应用程序启动时一次又一次地重新创建所有geofences,而是创建一次,然后再重用它们 但我不知道怎么做。当我启动我的应用程序时,geofenginemo

我正在开发UWP应用程序,它将帮助我所在城市的人们使用公共交通工具。当设备靠近某个站点时,它使用地理围栏进行通知。一切正常,但进展缓慢。在我的Lumia830上,为所有250个地理围栏准备数据并创建它们需要4-5秒。由于geofencemonitor在系统下运行,即使在我的应用程序终止时也可以存储我的geofences,所以我认为最好不要在每次应用程序启动时一次又一次地重新创建所有geofences,而是创建一次,然后再重用它们

但我不知道怎么做。当我启动我的应用程序时,
geofenginemonitor.Current.Count
为250,并且
geofenginemonitor.Current.Status
已准备就绪,但它从未触发Geoface state changed事件

我的问题是: 我试图在geofencemonitor中重用geofences。当我运行我的应用程序并且在启动期间,我调用geofenginemonitor.Current.geofengines.Clear();然后创建并添加所有my geofence->geofence状态更改事件从未触发

编辑:似乎,在我将geofence添加到geofencemonitor后,geofence状态更改只触发一次,在应用程序是否重新启动时独立启动。但“使用过的”土工栅栏仍保留在土工栅栏监视器中。geofence是否有某种不稳定状态?我是不是少了一些土工围栏的财产

以下是我创建geofence的方法:

var geofence = new Geofence(id, geocircle, mask, false, dwellTime);

GeofenceMonitor.Current.Geofences.Add(geofence);
我的问题是:
  • “因为,geofencemonitor在系统下运行,即使我的应用程序终止,也可以存储我的geofences”-这是真的吗
  • 如果我的第一个问题是真的,并且有可能重用地理围栏,那么我做错了什么,或者你知道我可以在UWP中深入研究地理围栏的地方吗
  • 谢谢你的建议

    以下是我如何收听geofences状态更改事件:

    ItsValueIs250 = Geofencemonitor.Current.Geofences.Count;
    ItsValueIsReady = Geofencemonitor.Current.Status;
    public async void OnGeofenceStateChanged(GeofenceMonitor sender, object e)
    {
        var reports = sender.ReadReports();
    
        await Dispatcher.DispatchAsync( () =>
        {
            foreach (GeofenceStateChangeReport report in reports)
            {
                GeofenceState state = report.NewState;
    
                Geofence geofence = report.Geofence;
    
    
                if (state == GeofenceState.Entered)
                {
                    stationInRange.Add(geofence.Id);
                    StationInRangeCount = stationInRange.Count().ToString();
    
                }
                else if (state == GeofenceState.Exited)
                {
                    stationInRange.Remove(geofence.Id);
    
    
                }
            }
        });
    }
    
    可能是我在启动时调用的这个方法

    async public Task<string> GeomonitorInitialize()
    {
    
        string message = string.Empty;
        var accessStatus = await Geolocator.RequestAccessAsync();
        switch (accessStatus)
        {
            case GeolocationAccessStatus.Allowed:
    
                int i = 0;
                i = GeofenceMonitor.Current.Geofences.Count;
                return message;
    
    
    
            case GeolocationAccessStatus.Denied:
                message = "GeoDenied";
                return message;
    
            case GeolocationAccessStatus.Unspecified:
                message = "GeoError";
                return message;
    
            default:
                message = "Default";
                return message;
        }
    
    }
    
    异步公共任务gemonitorialize()
    {
    string message=string.Empty;
    var accessStatus=await geologitor.RequestAccessAsync();
    开关(访问状态)
    {
    案例地理位置访问状态。允许:
    int i=0;
    i=GeofenceMonitor.Current.Geofences.Count;
    返回消息;
    案例地理位置访问状态。拒绝:
    message=“GeoDenied”;
    返回消息;
    案例地理位置访问状态。未指定:
    message=“georerror”;
    返回消息;
    违约:
    message=“Default”;
    返回消息;
    }
    }
    

    我将添加我使用的任何代码,如您所愿。谢谢。

    你有没有想过?我现在也有同样的问题。事件只触发一次。你知道吗?我现在也有同样的问题。事件只触发一次。