コード例 #1
0
        public static TimeSpan GetTimeForGoingTo(GeoCoords fromPos, GeoCoords toPos, double speed /*, bool betweenPoints = false*/)
        {
            //int distance = GoogleApi.GetWalkingDistance(fromPos, toPos);
            int distance = GeoCoords.Distance(fromPos, toPos);

            return(GetTimeForGoingTo(distance, speed /*, betweenPoints*/));
        }
コード例 #2
0
        private void AddNetwork(object sender, EventArgs e)
        {
            Android.Support.V7.App.AlertDialog.Builder alertDialog = new Android.Support.V7.App.AlertDialog.Builder(Activity);
            var localView = Activity.LayoutInflater.Inflate(Resource.Layout.MainDialog, null);

            alertDialog.SetView(localView);
            alertDialog.SetTitle("Add new network");
            var name   = localView.FindViewById <TextInputEditText>(Resource.Id.textInputEditText1);
            var button = localView.FindViewById <Button>(Resource.Id.changeLocationButton);

            coords        = new GeoCoords(45, 45);
            view          = localView;
            button.Click += OnPickAPlaceButtonTapped;
            alertDialog.SetNeutralButton("OK", async delegate
            {
                if (name.Text != String.Empty)
                {
                    await adapter.AddNetwork(name.Text, coords);
                }
                alertDialog.Dispose();
            });
            alertDialog.SetNegativeButton("Cancel", delegate
            {
                alertDialog.Dispose();
            });
            alertDialog.Show();
        }
コード例 #3
0
            public static int Distance(GeoCoords a, GeoCoords b)
            {
                {
                    int earthRadius = 6372795;

                    // перевести координаты в радианы
                    double lat1  = a.xCoord * Math.PI / 180;
                    double lat2  = b.xCoord * Math.PI / 180;
                    double long1 = a.yCoord * Math.PI / 180;
                    double long2 = b.yCoord * Math.PI / 180;

                    // косинусы и синусы широт и разницы долгот
                    double cl1    = Math.Cos(lat1);
                    double cl2    = Math.Cos(lat2);
                    double sl1    = Math.Sin(lat1);
                    double sl2    = Math.Sin(lat2);
                    double delta  = long2 - long1;
                    double cdelta = Math.Cos(delta);
                    double sdelta = Math.Sin(delta);

                    // вычисления длины большого круга
                    double y = Math.Sqrt(Math.Pow(cl2 * sdelta, 2) + Math.Pow(cl1 * sl2 - sl1 * cl2 * cdelta, 2));
                    double x = sl1 * sl2 + cl1 * cl2 * cdelta;

                    //
                    double ad   = Math.Atan2(y, x);
                    double dist = ad * earthRadius;

                    dist = Math.Atan2(Math.Sqrt(Math.Pow(Math.Cos(b.xCoord * Math.PI / 180) * Math.Sin((b.yCoord - a.yCoord) * Math.PI / 180), 2) + Math.Pow(Math.Cos(a.xCoord * Math.PI / 180) * Math.Sin(b.xCoord * Math.PI / 180) - Math.Sin(a.xCoord * Math.PI / 180) * Math.Cos(b.xCoord * Math.PI / 180) * Math.Cos((b.yCoord - a.yCoord) * Math.PI / 180), 2)), Math.Sin(a.xCoord * Math.PI / 180) * Math.Sin(b.xCoord * Math.PI / 180) + Math.Cos(a.xCoord * Math.PI / 180) * Math.Cos(b.xCoord * Math.PI / 180) * Math.Cos((b.yCoord - a.yCoord) * Math.PI / 180)) * 6372795;

                    return((int)Math.Round(dist, 0));
                }
            }
コード例 #4
0
            public static int Distance(GeoCoords a, GeoCoords b)
            {
                {
                    // перевести координаты в радианы
                    double lat1  = a.lat * pi180;
                    double lat2  = b.lat * pi180;
                    double long1 = a.lng * pi180;
                    double long2 = b.lng * pi180;

                    // косинусы и синусы широт и разницы долгот
                    double cl1    = TaylorCos(lat1);
                    double cl2    = TaylorCos(lat2);
                    double sl1    = TaylorSin(lat1);
                    double sl2    = TaylorSin(lat2);
                    double delta  = long2 - long1;
                    double cdelta = TaylorCos(delta);
                    double sdelta = TaylorSin(delta);

                    // вычисления длины большого круга
                    double tmp = cl2 * cdelta;
                    double y   = Math.Sqrt(cl2 * cl2 * sdelta * sdelta + (cl1 * sl2 - sl1 * tmp) * (cl1 * sl2 - sl1 * tmp));
                    double x   = sl1 * sl2 + cl1 * tmp;

                    //
                    double ad   = Math.Atan2(y, x);        //TaylorAtan(y/x);
                    int    dist = (int)(ad * earthRadius); //(int)Math.Round(ad * earthRadius, 0);

                    //double dist2 = Math.Atan2(Math.Sqrt(Math.Pow(Math.Cos(b.xCoord * Math.PI / 180) * Math.Sin((b.yCoord - a.yCoord) * Math.PI / 180), 2) + Math.Pow(Math.Cos(a.xCoord * Math.PI / 180) * Math.Sin(b.xCoord * Math.PI / 180) - Math.Sin(a.xCoord * Math.PI / 180) * Math.Cos(b.xCoord * Math.PI / 180) * Math.Cos((b.yCoord - a.yCoord) * Math.PI / 180), 2)), Math.Sin(a.xCoord * Math.PI / 180) * Math.Sin(b.xCoord * Math.PI / 180) + Math.Cos(a.xCoord * Math.PI / 180) * Math.Cos(b.xCoord * Math.PI / 180) * Math.Cos((b.yCoord - a.yCoord) * Math.PI / 180)) * 6372795;
                    //dist2 = (int)Math.Round(dist2, 0);

                    return(dist);
                }
            }
コード例 #5
0
        public async Task <GeoCoords> GetGeoCoordinatesAsync()
        {
            var locator = CrossGeolocator.Current;

            locator.DesiredAccuracy = 30;

            var position = await locator.GetPositionAsync(30000);

            if (position == null)
            {
                var result = new GeoCoords
                {
                    Latitude  = 0,
                    Longitude = 0
                };

                return(result);
            }
            else
            {
                var result = new GeoCoords
                {
                    Latitude  = position.Latitude,
                    Longitude = position.Longitude
                };

                return(result);
            }
        }
コード例 #6
0
        public static GeoCoords GetCoords(string adress, GeoCoords crds = null)
        {
            string request = "https://maps.googleapis.com/maps/api/geocode/json?address=" + adress.Replace("&", "");
            string point   = null;

            if (crds != null)
            {
                string x = crds.xCoord.ToString(System.Globalization.CultureInfo.InvariantCulture);
                string y = crds.yCoord.ToString(System.Globalization.CultureInfo.InvariantCulture);
                point    = ("&bounds=" + x + "," + y + "|" + x + "," + y).ToString();
                request += point;
            }

            WebRequest  req  = WebRequest.Create(request);
            WebResponse resp = req.GetResponse();

            Stream       stream = resp.GetResponseStream();
            StreamReader sr     = new StreamReader(stream);
            string       result = sr.ReadToEnd();

            sr.Close();

            Regex regexX = new Regex("(?<=\"location\"(\\s)*:(\\s)*{(\\s)*\"lat\"(\\s)*:(\\s)*)([0-9]+.[0-9]+)(?=(\\s)*,(\\s)*\"lng\"(\\s)*:(\\s)*[0-9]+.[0-9]+(\\s)*}(\\s)*,(\\s)*)");
            Regex regexY = new Regex("(?<=\"location\"(\\s)*:(\\s)*{(\\s)*\"lat\"(\\s)*:(\\s)*[0-9]+.[0-9]+(\\s)*,(\\s)*\"lng\"(\\s)*:(\\s)*)([0-9]+.[0-9]+)(?=(\\s)*}(\\s)*,(\\s)*)");

            double xCoord = double.Parse(regexX.Match(result).Value, System.Globalization.CultureInfo.InvariantCulture);
            double yCoord = double.Parse(regexY.Match(result).Value, System.Globalization.CultureInfo.InvariantCulture);

            return(new GeoCoords(Math.Round(xCoord, 4), Math.Round(yCoord, 4)));
        }
コード例 #7
0
        public void Test_Evaluate(double t, string c, double h,
                                  double D_, double I_, double H_, double By_, double Bx_, double Bz_, double F_,
                                  double Dt_, double It_, double Ht_, double Byt_, double Bxt_, double Bzt_, double Ft_)
        {
            var tolerance = 1e-10;
            var coord     = new GeoCoords(c);

            var model = new MagneticModel("wmm2020",
                                          Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "magnetic"));

            var(Bx, By, Bz) = model.Evaluate(t, coord.Latitude, coord.Longitude, h, out var Bxt, out var Byt, out var Bzt);

            var(H, F, D, I) = MagneticModel.FieldComponents(Bx, By, Bz, Bxt, Byt, Bzt,
                                                            out var Ht, out var Ft, out var Dt, out var It);

            Assert.AreEqual(D_, D, tolerance);
            Assert.AreEqual(I_, I, tolerance);
            Assert.AreEqual(H_, H, tolerance);
            Assert.AreEqual(By_, By, tolerance);
            Assert.AreEqual(Bx_, Bx, tolerance);
            Assert.AreEqual(Bz_, -Bz, tolerance);
            Assert.AreEqual(F_, F, tolerance);

            Assert.AreEqual(Dt_, Dt, tolerance);
            Assert.AreEqual(It_, It, tolerance);
            Assert.AreEqual(Ht_, Ht, tolerance);
            Assert.AreEqual(Byt_, Byt, tolerance);
            Assert.AreEqual(Bxt_, Bxt, tolerance);
            Assert.AreEqual(Bzt_, -Bzt, tolerance);
            Assert.AreEqual(Ft_, Ft, tolerance);
        }
コード例 #8
0
 public Point(TimeSpan totalTime, GeoCoords crds, Station fromWhere = null, Route r = null)
 {
     station        = null;
     coords         = crds;
     this.totalTime = totalTime;
     this.fromWhere = fromWhere;
     this.myRoute   = r;
 }
コード例 #9
0
 public Point(TimeSpan totalTime, Station station, Station fromWhere = null, Route r = null)
 {
     this.station   = station;
     coords         = station.Coords;
     this.totalTime = totalTime;
     this.fromWhere = fromWhere;
     this.myRoute   = r;
 }
コード例 #10
0
        private void GetPlaceFromPicker(Intent data)
        {
            IPlace placePicked  = PlacePicker.GetPlace(Activity, data);
            var    locationText = view.FindViewById <TextView>(Resource.Id.locationText);

            locationText.Text = String.Format("Location:({0},{1})", placePicked.LatLng.Latitude, placePicked.LatLng.Longitude);
            coords            = new GeoCoords(placePicked.LatLng.Latitude, placePicked.LatLng.Longitude);
        }
コード例 #11
0
        public void AssignDistancesBetweenPackages(List <Package> packingList, Address courierAddress) // BARDZO BRZYDKIE POMYŚL SOBIE JAK TO UŁADNIĆ
        {
            var previousPackage = new Package();

            foreach (var currentPackage in packingList)
            {
                var fromSender = new GeoCoords();
                var toSender   = new GeoCoords();

                var fromReceiver = new GeoCoords();
                var toReceiver   = new GeoCoords();

                if (packingList.First() == currentPackage)
                {
                    fromSender.Latitude  = courierAddress.Latitude;
                    fromSender.Longitude = courierAddress.Longitude;

                    toSender.Latitude  = currentPackage.Sender.Address.Latitude;
                    toSender.Longitude = currentPackage.Sender.Address.Longitude;

                    fromReceiver.Latitude  = packingList.Last().Sender.Address.Latitude;
                    fromReceiver.Longitude = packingList.Last().Sender.Address.Longitude;

                    toReceiver.Latitude  = currentPackage.Receiver.Address.Latitude;
                    toReceiver.Longitude = currentPackage.Receiver.Address.Longitude;
                }

                else
                {
                    fromSender.Latitude  = previousPackage.Sender.Address.Latitude;
                    fromSender.Longitude = previousPackage.Sender.Address.Longitude;

                    toSender.Latitude  = currentPackage.Sender.Address.Latitude;
                    toSender.Longitude = currentPackage.Sender.Address.Longitude;

                    fromReceiver.Latitude  = previousPackage.Receiver.Address.Latitude;
                    fromReceiver.Longitude = previousPackage.Receiver.Address.Longitude;

                    toReceiver.Latitude  = currentPackage.Receiver.Address.Latitude;
                    toReceiver.Longitude = currentPackage.Receiver.Address.Longitude;
                }

                currentPackage.SenderDistanceFromPreviousPoint   = _geoMapService.CalculateDistanceBetweenTwoPoints(fromSender.Latitude, fromSender.Longitude, toSender.Latitude, toSender.Longitude);
                currentPackage.ReceiverDistanceFromPreviousPoint = _geoMapService.CalculateDistanceBetweenTwoPoints(fromReceiver.Latitude, fromReceiver.Longitude, toReceiver.Latitude, toReceiver.Longitude);

                previousPackage = currentPackage;
            }

            using (var context = _dbContextFactoryMethod())
            {
                foreach (var package in packingList)
                {
                    context.Packages.Update(package);
                }

                context.SaveChanges();
            }
        }
コード例 #12
0
        public async Task <object> GetWeatherInfo()
        {
            GeoCoords burgasCoords = new GeoCoords
            {
                Latitude  = 42.5048,
                Longitude = 27.4626
            };

            return(await _weather.GetWeatherInfoAsync(burgasCoords));
        }
コード例 #13
0
        public void Test_EvaluateWithoutCache(string c, double height)
        {
            using (var geoid = new Geoid("egm84-30",
                                         Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "geoids")))
            {
                var coord = new GeoCoords(c);
                var h     = geoid.Evaluate(coord);

                Assert.AreEqual(height, h, 1e-4);
            }
        }
コード例 #14
0
        public async Task <GeoCoords> PullCoordinatesAsync()
        {
            var locator     = new Geolocator();
            var coordinates = await locator.GetGeopositionAsync();

            GeoCoords result = new GeoCoords();

            result.Latitude  = coordinates.Coordinate.Point.Position.Latitude;
            result.Longitude = coordinates.Coordinate.Point.Position.Longitude;

            return(result);
        }
コード例 #15
0
 public void Test_Evaluate(string coord, double height, double GX, double GY, double GZ)
 {
     var c     = new GeoCoords(coord);
     var model = new GravityModel("egm96",
                                  Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "gravity"));
     {
         var(_, gx, gy, gz) = model.Gravity(c.Latitude, c.Longitude, height);
         Assert.AreEqual(GX, gx, 1e-5);
         Assert.AreEqual(GY, gy, 1e-5);
         Assert.AreEqual(GZ, gz, 1e-5);
     }
 }
コード例 #16
0
        public async Task <GeoCoords> GetGeoCoordinatesAsync()
        {
            var geolocator  = new Windows.Devices.Geolocation.Geolocator();
            var geoposition = await geolocator.GetGeopositionAsync();

            var coords = new GeoCoords
            {
                Latitude  = geoposition.Coordinate.Latitude,
                Longitude = geoposition.Coordinate.Longitude
            };

            return(coords);
        }
コード例 #17
0
ファイル: MainAdapter.cs プロジェクト: veselink1/SunRays
        public async Task AddNetwork(string name, GeoCoords coords)
        {
            Network      net = new Network(name);
            SolarNetwork sn  = new SolarNetwork();

            sn.Name       = net.Name;
            sn.Longtitude = coords.Longitude;
            sn.Latitude   = coords.Latitude;
            net.ID        = (int)await db.SolarNetworks.InsertAsync(sn);

            netList.Add(net);
            UpdateAdapter();
        }
コード例 #18
0
        public async Task <GeoCoords> GetGeoCoordinatesAsync()
        {
            var locator = new Geolocator {
                DesiredAccuracy = 30
            };
            var position = await locator.GetPositionAsync(30000);

            var result = new GeoCoords
            {
                Latitude  = position.Latitude,
                Longitude = position.Longitude
            };

            return(result);
        }
コード例 #19
0
        public async Task <VenuesResponse> GetVenues(string query, GeoCoords coords)
        {
            var v = DateTime.Now.ToString("yyyyMMdd");

            var ll = string.Format("{0},{1}", coords.Latitude, coords.Longitude);

            var url = string.Format(@"https://api.foursquare.com/v2/venues/search?ll={0}&query={1}&client_id={2}&client_secret={3}&v={4}", ll, query, _CLIENT_ID, _CLIENT_SECRET, v);

            var client   = new HttpClient();
            var response = await client.GetStringAsync(url);

            JObject o = JObject.Parse(response);

            return(await Task.Factory.StartNew(() => JsonConvert.DeserializeObject <VenuesResponse>(o["response"].ToString())));
        }
コード例 #20
0
 static void Main(string[] args)
 {
     try {
         // Miscellaneous conversions
         double lat = 33.3, lon = 44.4;
         GeoCoords c = new GeoCoords(lat, lon, -1);
         Console.WriteLine(c.MGRSRepresentation(-3));
         c.Reset("18TWN0050", true, false);
         Console.WriteLine(c.DMSRepresentation(0, false, 0));
         Console.WriteLine(String.Format("Latitude: {0} Longitude: {1}", c.Latitude, c.Longitude));
         c.Reset("1d38'W 55d30'N", true, false);
         Console.WriteLine(c.GeoRepresentation(0, false));
     }
     catch (GeographicErr e) {
         Console.WriteLine(String.Format("Caught exception: {0}", e.Message));
     }
 }
コード例 #21
0
ファイル: example-GeoCoords.cs プロジェクト: eglrp/GraphSlam
 static void Main(string[] args)
 {
     try {
         // Miscellaneous conversions
         double    lat = 33.3, lon = 44.4;
         GeoCoords c = new GeoCoords(lat, lon, -1);
         Console.WriteLine(c.MGRSRepresentation(-3));
         c.Reset("18TWN0050", true, false);
         Console.WriteLine(c.DMSRepresentation(0, false, 0));
         Console.WriteLine(String.Format("Latitude: {0} Longitude: {1}", c.Latitude, c.Longitude));
         c.Reset("1d38'W 55d30'N", true, false);
         Console.WriteLine(c.GeoRepresentation(0, false));
     }
     catch (GeographicErr e) {
         Console.WriteLine(String.Format("Caught exception: {0}", e.Message));
     }
 }
コード例 #22
0
        public static int GetWalkingDistance(GeoCoords from, GeoCoords to)
        {
            string request = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=" + from.xCoord.ToString(System.Globalization.CultureInfo.InvariantCulture) + "," + from.yCoord.ToString(System.Globalization.CultureInfo.InvariantCulture) + "&destinations=" + to.xCoord.ToString(System.Globalization.CultureInfo.InvariantCulture) + "," + to.yCoord.ToString(System.Globalization.CultureInfo.InvariantCulture) + "&mode=walking";

            WebRequest  req  = WebRequest.Create(request);
            WebResponse resp = req.GetResponse();

            Stream       stream = resp.GetResponseStream();
            StreamReader sr     = new StreamReader(stream);
            string       result = sr.ReadToEnd();

            sr.Close();

            Regex regex = new Regex("(?<=(\\s)*{(\\s)*\"distance\"(\\s)*:(\\s)*{(\\s)*\"text\"(\\s)*:(\\s)*\"[0-9]+(,)?(\\s)*([0-9]+)?(\\s)*(\\w)+\"(\\s)*,(\\s)*\"value\"(\\s)*:(\\s)*)([0-9]+)(?=(\\s)*}(\\s)*,(\\s)*\"duration\")");

            return(int.Parse(regex.Match(result).Value));
        }
コード例 #23
0
        public void TestInverse(string p1, string p2, double azi12, double s12, double S12, bool exact)
        {
            var c1 = new GeoCoords(p1);
            var c2 = new GeoCoords(p2);

            var rhumb = new Rhumb(Ellipsoid.WGS84, exact);

            rhumb.Inverse(c1.Latitude, c1.Longitude, c2.Latitude, c2.Longitude, out var _s12, out var _azi12, out var _S12);
            Assert.AreEqual(azi12, _azi12, 1e-8);
            Assert.AreEqual(s12, _s12, 1e-8);
            Assert.AreEqual(S12, _S12, 0.05);

            var result = rhumb.Inverse(c1.Latitude, c1.Longitude, c2.Latitude, c2.Longitude);

            Assert.AreEqual(azi12, result.Azimuth, 1e-8);
            Assert.AreEqual(s12, result.Distance, 1e-8);
            Assert.AreEqual(S12, result.Area, 0.05);
        }
コード例 #24
0
ファイル: TestInit.cs プロジェクト: umbgtt10/TripLogJuventus
        static TestInit()
        {
            FakeCoordinates = new GeoCoords();

            FakeCoordinates.Latitude  = 123;
            FakeCoordinates.Longitude = 321;

            FakeTripLogEntryCollection = new List <TripLogEntry>()
            {
                new TripLogEntry()
            };

            MockedTripLogDataService.Setup(query => query.ReadAllEntriesAsync()).
            ReturnsAsync(FakeTripLogEntryCollection);

            MockedGeoLocationService.Setup(query => query.PullCoordinatesAsync()).
            ReturnsAsync(FakeCoordinates);
        }
コード例 #25
0
        public void TestDirect(string p1, string p2, double azi12, double s12, double S12, bool exact)
        {
            var c1 = new GeoCoords(p1);
            var c2 = new GeoCoords(p2);

            var rhumb = new Rhumb(Ellipsoid.WGS84, exact);

            rhumb.Direct(c1.Latitude, c1.Longitude, azi12, s12, out var _lat2, out var _lon2, out var _S12);
            Assert.AreEqual(c2.Latitude, _lat2, 1e-8);
            Assert.AreEqual(c2.Longitude, _lon2, 1e-8);
            Assert.AreEqual(S12, _S12, 0.01);

            var result = rhumb.Direct(c1.Latitude, c1.Longitude, azi12, s12);

            Assert.AreEqual(c2.Latitude, result.Latitude, 1e-8);
            Assert.AreEqual(c2.Longitude, result.Longitude, 1e-8);
            Assert.AreEqual(S12, result.Area, 0.01);
        }
コード例 #26
0
        public static List <int> GetWalkingDistances(GeoCoords from, IEnumerable <GeoCoords> toArray)
        {
            if (toArray.Count() > 25)
            {
                throw new Exception();
            }

            StringBuilder sb = new StringBuilder();

            foreach (GeoCoords crds in toArray)
            {
                sb.Append(Math.Round(crds.xCoord, 4).ToString(System.Globalization.CultureInfo.InvariantCulture) + "," + Math.Round(crds.yCoord, 4).ToString(System.Globalization.CultureInfo.InvariantCulture) + "|");
            }
            sb.Remove(sb.Length - 1, 1);

            string request = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=" + from.xCoord.ToString(System.Globalization.CultureInfo.InvariantCulture) + "," + from.yCoord.ToString(System.Globalization.CultureInfo.InvariantCulture) + "&destinations=" + sb.ToString() + "&mode=walking";

            WebRequest  req  = WebRequest.Create(request);
            WebResponse resp = req.GetResponse();

            Stream       stream = resp.GetResponseStream();
            StreamReader sr     = new StreamReader(stream);
            string       result = sr.ReadToEnd();

            sr.Close();

            Regex regex = new Regex("(?<=(\\s)*{(\\s)*\"distance\"(\\s)*:(\\s)*{(\\s)*\"text\"(\\s)*:(\\s)*\"[0-9]+(,)?(\\s)*([0-9]+)?(\\s)*(\\w)+\"(\\s)*,(\\s)*\"value\"(\\s)*:(\\s)*)([0-9]+)(?=(\\s)*}(\\s)*,(\\s)*\"duration\")");

            List <int>      distances = new List <int>();
            MatchCollection mc        = regex.Matches(result);

            foreach (Match m in mc)
            {
                distances.Add(int.Parse(m.Value));
            }

            if (distances.Count != toArray.Count())
            {
                throw new Exception();
            }

            return(distances);
        }
コード例 #27
0
        static TestInit()
        {
            FakeCoordinates = new GeoCoords {
                Latitude = 123, Longitude = 321
            };
            FakeTripLogEntryCollection = new List <TripLogEntry>()
            {
                new TripLogEntry()
            };

            MockedGeoLocationService.Setup(query => query.PullCoordinatesAsync()).
            ReturnsAsync(FakeCoordinates);

            MockedTripLogDataService.Setup(query => query.AddEntryAsync(new TripLogEntry()));
            MockedTripLogDataService.Setup(query => query.ReadAllEntriesAsync()).
            ReturnsAsync(FakeTripLogEntryCollection);

            ViewModelFactory = new ViewModelFactory(MockedGeoLocationService.Object, MockedTripLogDataService.Object);
        }
コード例 #28
0
        public List <GeoCoords> GetCourierRouteCoords(Vehicle courierVehicle)
        {
            if (courierVehicle.CourierPackingList.Count == 0)
            {
                return(null);
            }

            var coordsList = new List <GeoCoords>();

            var courierAddressCoords = new GeoCoords
            {
                Latitude  = courierVehicle.Driver.Address.Latitude,
                Longitude = courierVehicle.Driver.Address.Longitude
            };

            coordsList.Add(courierAddressCoords);

            foreach (var package in courierVehicle.CourierPackingList)
            {
                coordsList.Add(new GeoCoords
                {
                    Latitude  = package.Sender.Address.Latitude,
                    Longitude = package.Sender.Address.Longitude
                });
            }

            foreach (var package in courierVehicle.CourierPackingList)
            {
                coordsList.Add(new GeoCoords
                {
                    Latitude  = package.Receiver.Address.Latitude,
                    Longitude = package.Receiver.Address.Longitude
                });
            }

            coordsList.Add(courierAddressCoords);

            return(coordsList);
        }
コード例 #29
0
        public static List <int> GetWalkingDistances(GeoCoords from, IEnumerable <GeoCoords> toArray)
        {
            StringBuilder sb = new StringBuilder();

            foreach (GeoCoords crds in toArray)
            {
                sb.Append(Math.Round(crds.lat, 4).ToString(System.Globalization.CultureInfo.InvariantCulture) + "," + Math.Round(crds.lng, 4).ToString(System.Globalization.CultureInfo.InvariantCulture) + "|");
            }
            sb.Remove(sb.Length - 1, 1);

            string request = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=" + from.lat.ToString(System.Globalization.CultureInfo.InvariantCulture) + "," + from.lng.ToString(System.Globalization.CultureInfo.InvariantCulture) + "&destinations=" + sb.ToString() + "&mode=walking";

            WebRequest  req  = WebRequest.Create(request);
            WebResponse resp = req.GetResponse();

            Stream       stream = resp.GetResponseStream();
            StreamReader sr     = new StreamReader(stream);
            string       result = sr.ReadToEnd();

            sr.Close();

            dynamic apiResultObject = JsonConvert.DeserializeObject <dynamic>(result);

            if ((string)apiResultObject.status != "OK")
            {
                throw new Exception("Неудачный запрос к Google API.");
            }

            dynamic apiResultObjectElements = apiResultObject.rows[0].elements;

            List <int> distances = new List <int>();

            foreach (dynamic element in apiResultObjectElements)
            {
                distances.Add((int)element.distance.value);
            }

            return(distances);
        }
コード例 #30
0
ファイル: NetworkActivity.cs プロジェクト: veselink1/SunRays
        private async Task UpdateCardsAsync()
        {
            try
            {
                bool hasConnection = await CheckInternetConnectionAsync();

                if (!hasConnection)
                {
                    Snackbar.Make(FindViewById(Resource.Id.main_content), "No internet connection.", Snackbar.LengthShort).Show();
                    CallOnReconnect(async delegate { await UpdateCardsAsync(); });
                    return;
                }

                GeoCoords geoCoords = new GeoCoords {
                    Latitude = solarNetwork.Latitude, Longitude = solarNetwork.Longtitude
                };

                PVSystemInfo systemInfo = await PVSystemInfo.FromDBAsync(db, solarNetwork.ID);

                UpdatePVSystemInfo(systemInfo);

                WeatherInfo weatherInfo = await weatherProvider.GetWeatherInfoAsync(geoCoords);

                UpdateWeatherInfoView(weatherInfo);

                ConsumerInfo consumerInfo = await ConsumerInfo.FromDBAsync(db, solarNetwork.ID);

                UpdateConsumerInfo(consumerInfo);

                SystemSummary arraySummary = await GetArraySummaryAsync(weatherInfo);

                UpdateArraySummary(arraySummary, consumerInfo);
            }
            catch (Exception e)
            {
                Log.Error(ToString(), e.ToString());
            }
        }
コード例 #31
0
ファイル: NetworkActivity.cs プロジェクト: veselink1/SunRays
        private async Task <SystemSummary> GetArraySummaryAsync(WeatherInfo weatherInfo)
        {
            GeoCoords coords = new GeoCoords
            {
                Latitude  = solarNetwork.Latitude,
                Longitude = solarNetwork.Longtitude
            };

            TimeZone timeZone            = TimeZone.CurrentTimeZone;
            TimeSpan timeZoneOffset      = timeZone.GetUtcOffset(DateTime.Now);
            double   timeZoneOffsetHours = timeZoneOffset.Hours + timeZoneOffset.Minutes / 30.0;

            PVSystemInfo systemInfo = await PVSystemInfo.FromDBAsync(db, solarNetwork.ID);

            return(await systemInfo.GetSystemSummaryAsync(
                       powerCalculator,
                       pvWattsApiClient,
                       coords,
                       DateTime.Now,
                       timeZoneOffsetHours,
                       tempCelsius : weatherInfo.Temperature.Value - 273.15
                       ));
        }