首页 > 解决方案 > Xamarin GeoLocatorPlugin 在运行时更改 minDistance

问题描述

在我的 xamarin 应用程序中,我需要地理围栏。

我正在使用GeoLocatorPlugin

有没有办法在运行时(开始收听后)影​​响参数“minDistance”?

await StartListeningAsync(TimeSpan.FromSeconds(5), "minDistance");

背景:我想根据给定的“兴趣点”(它们与用户位置的距离)优化“位置更新(更改)”的间隔。

提前问候和谢谢。

标签: xamarinlocationgeofencing

解决方案


我目前正在通过网络服务获取时间和距离(我现在不是你的情况,但你可以做一些与此非常相似的事情),我像这样保存(设备的本地存储):

  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
        });

推荐阅读