Example #1
0
 public void stop(string args)
 {
     RunningInBackground = false;
     if (Geolocator != null)
     {
         Geolocator.Stop();
     }
 }
Example #2
0
        public void setConfig(string setConfigArgs)
        {
            if (Geolocator == null)
            {
                return;
            }

            if (Geolocator.IsActive)
            {
                Geolocator.PositionChanged -= OnGeolocatorOnPositionChanged;
                Geolocator.Stop();
            }

            if (string.IsNullOrWhiteSpace(setConfigArgs))
            {
                DispatchCommandResult(new PluginResult(PluginResult.Status.INVALID_ACTION, "Cannot set config because of an empty input"));
                return;
            }
            var parsingSucceeded = true;

            var options = JsonHelper.Deserialize <string[]>(setConfigArgs);

            double stationaryRadius, distanceFilter;
            UInt32 locationTimeout, desiredAccuracy;

            if (!double.TryParse(options[0], out stationaryRadius))
            {
                DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION, string.Format("Invalid value for stationaryRadius:{0}", options[2])));
                parsingSucceeded = false;
            }
            if (!double.TryParse(options[1], out distanceFilter))
            {
                DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION, string.Format("Invalid value for distanceFilter:{0}", options[3])));
                parsingSucceeded = false;
            }
            if (!UInt32.TryParse(options[2], out locationTimeout))
            {
                DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION, string.Format("Invalid value for locationTimeout:{0}", options[4])));
                parsingSucceeded = false;
            }
            if (!UInt32.TryParse(options[3], out desiredAccuracy))
            {
                DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION, string.Format("Invalid value for desiredAccuracy:{0}", options[5])));
                parsingSucceeded = false;
            }
            if (!parsingSucceeded)
            {
                return;
            }

            BackgroundGeoLocationOptions.StationaryRadius         = stationaryRadius;
            BackgroundGeoLocationOptions.DistanceFilterInMeters   = distanceFilter;
            BackgroundGeoLocationOptions.LocationTimeoutInSeconds = locationTimeout * 1000;
            BackgroundGeoLocationOptions.DesiredAccuracyInMeters  = desiredAccuracy;

            Geolocator = new GeolocatorWrapper(desiredAccuracy, locationTimeout * 1000, distanceFilter, stationaryRadius);
            Geolocator.PositionChanged += OnGeolocatorOnPositionChanged;
            Geolocator.Start();

            DispatchCommandResult(new PluginResult(PluginResult.Status.OK));
        }