Пример #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);
        }
Пример #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;
        }