Ejemplo n.º 1
0
        public void read( latLon position )
        {
            string[] grids = position.getGrids();

            string parameter = "?cf_gridP=" + grids[0];
            for (int i = 1; i < position.getGridCount(); i++)
                parameter += "&cf_grid" + i + "=" + grids[i];

            parameter += "&cf_sys_lat=" + position.getSysLat();
            parameter += "&cf_sys_lon=" + position.getSysLon();

            Uri readUri = new Uri(readUrl + parameter, UriKind.Absolute);

            client.OpenReadAsync(readUri);
            asyncWait.WaitOne(DB_PULL_WAIT_TIME);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
0
        public readData read()
        {
            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);

            StringBuilder htmlOutput = new StringBuilder("");

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

            db.read(position);

            readData output = JsonConvert.DeserializeObject<readData>(htmlOutput.ToString());

            return output;
        }