Пример #1
0
        public void getCurrentLatLonRage()
        {
            /* Get Current location */
            GeoCoordinateWatcher getPosition = new GeoCoordinateWatcher();

            int geoGetTry = 3; //times...
            bool gotGeoRespond = false;

            while (geoGetTry-- > 0 && gotGeoRespond == false)
            {
                gotGeoRespond = getPosition.TryStart(false, TimeSpan.FromMilliseconds(1000));
            }

            /*
             * Only update current location if is good location
             * else just use what we have before
             */
            if (gotGeoRespond == true)
            {
                lat = (float)getPosition.Position.Location.Latitude;
                lon = (float)getPosition.Position.Location.Longitude;
            }

            getPosition.Stop();
            getPosition.Dispose();

            latLon position = new latLon(lat, lon);
            double r = (double)App.distancesMeter[App.ReadSettings.radiusMetersIndx] / (double)App.R;

            double latRad = mathPlus.DegreeToRadian((double)position.getLat());
            latStart = (float)mathPlus.RadianToDegree(latRad - r);
            latEnd = (float)mathPlus.RadianToDegree(latRad + r);

            double lonRad = mathPlus.DegreeToRadian((double)position.getLon());
            double tLon = Math.Asin(Math.Sin(r) / Math.Cos(latRad));
            lonStart = (float)mathPlus.RadianToDegree(lonRad - tLon);
            lonEnd = (float)mathPlus.RadianToDegree(lonRad + tLon);
        }
Пример #2
0
        public bool write(int radiusMeters, string title, string msg, bool showLocation)
        {
            GeoCoordinateWatcher getPosition = new GeoCoordinateWatcher();
            getPosition.TryStart(false, TimeSpan.FromMilliseconds(1000));

            float lat = (float)getPosition.Position.Location.Latitude;
            float lon = (float)getPosition.Position.Location.Longitude;

            getPosition.Stop();
            getPosition.Dispose();

            latLon position = new latLon(lat, lon);
            double r = (double)radiusMeters / (double)R;
            int gridI = -1;

            double latRad = mathPlus.DegreeToRadian((double)position.getLat());
            float latStart = (float)mathPlus.RadianToDegree(latRad - r);
            float latEnd = (float)mathPlus.RadianToDegree(latRad + r);

            double lonRad = mathPlus.DegreeToRadian((double)position.getLon());
            double tLon = Math.Asin(Math.Sin(r) / Math.Cos(latRad));
            float lonStart = (float)mathPlus.RadianToDegree(lonRad - tLon);
            float lonEnd = (float)mathPlus.RadianToDegree(lonRad + tLon);

            latLon nw = new latLon(latStart, lonStart);
            latLon ne = new latLon(latStart, lonEnd);
            latLon se = new latLon(latEnd, lonEnd);
            latLon sw = new latLon(latEnd, lonStart);

            string[] nwGrid = nw.getGrids();
            string[] neGrid = ne.getGrids();
            string[] seGrid = se.getGrids();
            string[] swGrid = sw.getGrids();

            for (int i = 0; i < position.getGridCount(); i++)
            {
                if (nwGrid[i] == neGrid[i]
                && nwGrid[i] == seGrid[i]
                && nwGrid[i] == swGrid[i])
                {
                    gridI = i;
                    break;
                }
            }

            if (gridI < 0) return false;

            StringBuilder output = new StringBuilder("");

            DB db = new DB();
            db.setOutput(output);

            db.write( myUser.getUserID()
                , nwGrid[gridI]
                , position.getLat()
                , position.getLon()
                , position.getSysLat()
                , position.getSysLon()
                , nw.getSysLat()
                , sw.getSysLat()
                , nw.getSysLon()
                , ne.getSysLon()
                , radiusMeters
                , showLocation
                , title
                , msg
            );

            statusMsg status = JsonConvert.DeserializeObject<statusMsg>(output.ToString());

            return true;
        }