xamarin - Xamarin GeoLocatorPlugin 在运行时更改 minDistance
问题描述
在我的 xamarin 应用程序中,我需要地理围栏。
我正在使用GeoLocatorPlugin。
有没有办法在运行时(开始收听后)影响参数“minDistance”?
await StartListeningAsync(TimeSpan.FromSeconds(5), "minDistance");
背景:我想根据给定的“兴趣点”(它们与用户位置的距离)优化“位置更新(更改)”的间隔。
提前问候和谢谢。
解决方案
我目前正在通过网络服务获取时间和距离(我现在不是你的情况,但你可以做一些与此非常相似的事情),我像这样保存(设备的本地存储):
dynamic obj = JsonConvert.DeserializeObject<Rootobject>(responseString);
Application.Current.Properties["gps_distancia"] = obj.rssUser.gps_distancia;
Application.Current.Properties["gps_tempo"] = obj.rssUser.gps_tempo;
然后我调用来自网络服务的存储时间和距离并保存在设备中:
int tempoWebService = Int32.Parse(Application.Current.Properties["gps_tempo"].ToString());
int distanciaWebService = Int32.Parse(Application.Current.Properties["gps_distancia"].ToString());
await CrossGeolocator.Current.StartListeningAsync(TimeSpan.FromSeconds(tempoWebService), distanciaWebService, true, new Plugin.Geolocator.Abstractions.ListenerSettings
{
ActivityType = Plugin.Geolocator.Abstractions.ActivityType.AutomotiveNavigation,
AllowBackgroundUpdates = true,
DeferLocationUpdates = true,
DeferralDistanceMeters = 1,
DeferralTime = TimeSpan.FromSeconds(1),
ListenForSignificantChanges = true,
PauseLocationUpdatesAutomatically = false
});
推荐阅读
- asp.net - 错误:配置部分不能包含 CDATA 或文本元素
- r - 删除数据框中某个变量下的值为 0 的行
- eclipse - Eclipse 图标不清晰
- javascript - 如何将'>'添加到javascript中字符串的每个新行?
- html - 如何为条形图剪辑路径设置动画?
- java - Netty - 如何在 DDOS 中生存?
- node.js - 如何使用 sequelize 删除关联的行
- ionic-framework - 使用 android (Ionic 3) 中的 ImagePicker 插件重定向以在其他图像文件夹中查看
- python - 使用 marshmallow-mongoengine 加载数据时如何包含其他未知字段?
- scala - 无法从生成的原型中获取 parseFrom 作为可用方法