C#UWP,在geofencemonitor中重用geofences
我正在开发UWP应用程序,它将帮助我所在城市的人们使用公共交通工具。当设备靠近某个站点时,它使用地理围栏进行通知。一切正常,但进展缓慢。在我的Lumia830上,为所有250个地理围栏准备数据并创建它们需要4-5秒。由于geofencemonitor在系统下运行,即使在我的应用程序终止时也可以存储我的geofences,所以我认为最好不要在每次应用程序启动时一次又一次地重新创建所有geofences,而是创建一次,然后再重用它们 但我不知道怎么做。当我启动我的应用程序时,C#UWP,在geofencemonitor中重用geofences,c#,win-universal-app,geofencing,C#,Win Universal App,Geofencing,我正在开发UWP应用程序,它将帮助我所在城市的人们使用公共交通工具。当设备靠近某个站点时,它使用地理围栏进行通知。一切正常,但进展缓慢。在我的Lumia830上,为所有250个地理围栏准备数据并创建它们需要4-5秒。由于geofencemonitor在系统下运行,即使在我的应用程序终止时也可以存储我的geofences,所以我认为最好不要在每次应用程序启动时一次又一次地重新创建所有geofences,而是创建一次,然后再重用它们 但我不知道怎么做。当我启动我的应用程序时,geofenginemo
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);
我的问题是:
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”;
返回消息;
}
}
我将添加我使用的任何代码,如您所愿。谢谢。你有没有想过?我现在也有同样的问题。事件只触发一次。你知道吗?我现在也有同样的问题。事件只触发一次。