Beispiel #1
0
        // ===================================================================================================
        // Get geo location, and work with it
        //
        // 1) Get Latitude, Longitude, Altitude, Accuracy from current location
        // 2) Generate "100 miles" address list of hospitals in range. Post to button.
        // ===================================================================================================
        public static async Task GetDevLocationAsync_SectionA()
        {
            try
            {
                //
                // 1) Get Latitude, Longitude, Altitude, Accuracy from current location
                // -------------------------------------------------------------------------
                var georequest = new GeolocationRequest(GeolocationAccuracy.Best);
                var georesults = await Geolocation.GetLocationAsync(georequest);

                App.deviceLatitude    = Convert.ToDouble(georesults.Latitude.ToString());
                App.deviceLongitude   = Convert.ToDouble(georesults.Longitude.ToString());
                App.strAccuracyMeters = Convert.ToInt32(georesults.Accuracy).ToString();
                App.strAccuracyFeet   = (Convert.ToInt32(georesults.Accuracy) * 3.28).ToString();

                //
                // 2) Generate "100 miles" address list of hospitals in range.
                // -----------------------------------------------------------------------
                int atemp = (Convert.ToInt32(App.defaultHospitalRange));
                atemp = atemp * 100;
                App.requestedHospitalRange = atemp;
                //
                // Now get and load the 100-miles list
                //
                FlatData.Load_HospitalsInRage(App.deviceLatitude, App.deviceLongitude);
                //
            }
            catch (Exception ex)
            {
                string aa = ex.ToString();
                App.MajorError = true;
            }
        }
Beispiel #2
0
        // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
        // Load a two-dimensional array with
        // 1) all indexes (into hospitalsDB )
        // 2) distance for that index
        //
        // 1. get distance from target to every hospital
        // 2. if < 10/20/30/40 save in index array <hospital pointer, distance>
        // 3. sort the helper arrays by distance.
        //      We now have 5 arrays, sorted by distance, holding hospital pointers
        // 4. Fill the actual details arrays using the helper arrays
        // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
        public static void Load_HospitalsInRage(double inLatfrom, double inLongfrom)
        {
            //
            //
            bool     iB                  = true;
            Location coord1              = new Location(inLatfrom, inLongfrom);
            Location coord2              = new Location(inLatfrom, inLongfrom); // dummy entry, just to get location
            double   distanceInRadius    = 0.0f;
            Int32    intdistanceInRadius = 0;

            App.hospitalsInRangeCount = 0;
            if (inLatfrom <= 0.0)
            {
                iB = false;
            }
            if (inLongfrom <= 0.0)
            {
                iB = false;
            }

            try
            {
                //
                // Get Distance, and fill helper arrays
                //
                App.hospitalsInRangeCount = 0;
                for (int innn = 0; innn < App.hospitalsDBRowsCount; innn++)
                {
                    //
                    // 100 count
                    //
                    if (App.hospitalsInRangeCount == 101)
                    {
                        break;
                    }
                    // There are some records that have no Latitude / Longitude
                    // both cases will be handled by the abreviated catch {}
                    try
                    {
                        // Get 'radian' distance, i.e. "Birdview" distance between device-address and array entry
                        coord2              = new Location(Convert.ToDouble(App.hospitalsDB[innn, 8]), Convert.ToDouble(App.hospitalsDB[innn, 9]));
                        distanceInRadius    = Location.CalculateDistance(coord1, coord2, DistanceUnits.Miles);
                        intdistanceInRadius = Convert.ToInt32((distanceInRadius) * 100);
                        if (intdistanceInRadius < App.requestedHospitalRange)
                        {
                            App.hospitalsInRange[App.hospitalsInRangeCount, 0] = innn;
                            App.hospitalsInRange[App.hospitalsInRangeCount, 1] = intdistanceInRadius;
                            App.hospitalsInRangeCount++;
                            iB = false;
                        }
                    }
                    catch (Exception stre)
                    {
                        string aa = stre.Message.ToString();
                    }
                }
            }
            catch (Exception stre)
            {
                string aa = stre.Message.ToString();
            }

            if (App.hospitalsInRangeCount != 0)
            {
                App.hospitalsInRangeCount = App.hospitalsInRangeCount - 1;
            }


            //
            // sort helper arrays by distance
            //
            if (iB == false)
            {
                FlatData.SorthospitalsInRange();
            }
        }