public Coordinates GetPosition(int maxAge)
        {
            Coordinates retCoords = new Coordinates();

            if (_gpsDeviceState != null &&
                _gpsDeviceState.DeviceState == GpsServiceState.On &&
                _gpsDeviceState.ServiceState == GpsServiceState.On)
            {
                //TimeSpan maxage = new TimeSpan(0, 0, 1);
                GpsPosition position = _gps.GetPosition(maxAge);
                if (position.LatitudeValid && position.LongitudeValid)
                {
                    retCoords.Latitude = position.Latitude;
                    retCoords.Longitude = position.Longitude;
                }
            }

            return retCoords;
        }
        public static Coordinates GetLocation(RILCELLTOWERINFO t)
        {
            Coordinates coord = new Coordinates();
            try
            {
                string apiCall = OpenCellID_Service_Uri +
                    "&mnc=" + t.dwMobileNetworkCode +
                    "&mcc=" + t.dwMobileCountryCode +
                    "&lac=" + t.dwLocationAreaCode +
                    "&cellid=" + t.dwCellID;

                XmlDocument doc = new XmlDocument();
                doc.Load(apiCall);

                //EXAMPLE:
                // <cell mnc="99" lac="0" lat="50.5715642160311" nbSamples="57" range="6000" lon="25.2897075399231" cellId="29513" mcc="250"/>
                XmlNode rspNode = doc.SelectSingleNode("rsp");
                string status = rspNode.Attributes["stat"].Value;
                status.ToLower();

                if (status == "ok")
                {
                        XmlNode cellNode = rspNode.SelectSingleNode("cell");
                        int samples = int.Parse(cellNode.Attributes["nbSamples"].Value);

                        if (samples>0)
                        {
                            coord.Latitude = double.Parse(cellNode.Attributes["lat"].Value);
                            coord.Longitude = double.Parse(cellNode.Attributes["lon"].Value);
                            coord.Precision = double.Parse(cellNode.Attributes["range"].Value);
                        }
                }
            }
            catch
            { }
            return coord;
        }
        void OnBtnSetLocation(object Sender)
        {
            FormMap frmMap = new FormMap();
            frmMap.StartRadius = (int)(mTask.Radius * 1000);
            if (mTask.LocationCoord != null)
            {
                frmMap.StartPos = new PointLatLng(mTask.LocationCoord.Latitude, mTask.LocationCoord.Longitude);
            }
            if (Globals.ShowDialog(frmMap, this) == DialogResult.OK)
            {
                Coordinates coord = new Coordinates();
                coord.Latitude = frmMap.CenterCross.Position.Lat;
                coord.Longitude = frmMap.CenterCross.Position.Lng;
                mTask.LocationCoord = coord;
                mTask.Radius = (frmMap.RadiusCircle.Radius * 0.001f);

                Placemark place = GMaps.Instance.GetPlacemarkFromGeocoder(frmMap.CenterCross.Position);
                if (place != null)
                {
                    mTask.LocationAddress = place.Address;
                }
                else
                {
                    mTask.LocationAddress = frmMap.CenterCross.Position.ToString();
                }
                SetLocationAddress(mTask.LocationAddress);
            }
        }
        private bool ProcessTask(Task task, Coordinates currentPos)
        {
            if(!task.LocationCoord.IsValid()) return false;

            double distance = PositionTools.GetDistance(currentPos, task.LocationCoord);
            Globals.WriteToDebugFile("TaskMonitor: Task " + task.Subject + " distance: " + distance);
            if (distance > task.Radius) return false;

            _actionsMgr.ProcessTask(task);
            Globals.WriteToDebugFile("TaskMonitor: Processed task: " + task.Subject);
            return true;
        }
        public static double GetDistance(Coordinates coord1, Coordinates coord2)
        {
            if (coord1.IsValid() == false || coord2.IsValid() == false) return -1;

            return GetDistance(coord1.Latitude, coord1.Longitude, coord2.Latitude, coord2.Longitude);
        }