public async Task <UserCoordinates> retrieveUserLocation()
        {
            UserCoordinates c = new UserCoordinates();

            if (IsGPSRunning())
            {
                //Get current location.
                var locator  = CrossGeolocator.Current;
                var position = await locator.GetPositionAsync(TimeSpan.FromSeconds(10));



                c.longitude = position.Longitude;
                c.latitude  = position.Latitude;

                return(c);
            }

            else
            {
                c.longitude = 120.98158;
                c.latitude  = 14.60537;

                return(c);
            }
        }
        public async void OnMapReady(GoogleMap googleMap)
        {
            try
            {
                //retrieve your current location and current station based on dataset
                UserCoordinates c = new UserCoordinates();
                c = await retrieveUserLocation();



                Activity.RunOnUiThread(() =>
                {
                    MapsInitializer.Initialize(Activity);
                    this.GMap = googleMap;

                    GMap.UiSettings.ZoomControlsEnabled = true;
                    LatLng latlng       = new LatLng(c.latitude, c.longitude);
                    CameraUpdate camera = CameraUpdateFactory.NewLatLngZoom(latlng, 18);
                    GMap.AnimateCamera(camera);
                    GMap.UiSettings.ZoomControlsEnabled = false;

                    options = new MarkerOptions().SetPosition(latlng).SetTitle("My location");
                    GMap.AddMarker(options);
                });
            }
            catch (Exception ex)
            {
                Toast.MakeText(Activity, ex.Message, ToastLength.Short).Show();
            }
        }
        public static UserCoordinates Capture(UserCoordinates userCoordinates, string[] coordinatesFromTerminalArguments)
        {
            userCoordinates.Latitude = double.Parse(coordinatesFromTerminalArguments[0]);

            userCoordinates.Longitude = double.Parse(coordinatesFromTerminalArguments[1]);

            return(userCoordinates);
        }
Esempio n. 4
0
        public void NearestHardpoint_NearOrigin_ReturnsOriginHardpoint(float x, float y)
        {
            var uc = new UserCoordinates()
            {
                HardpointCoordinates = new PointF(x, y)
            };

            Assert.AreEqual(new Hardpoint(0, 0, 0), uc.NearestHardpoint());
        }
Esempio n. 5
0
        public void NearestNHardpoints_N5_Returns5Hardpoints()
        {
            var uc = new UserCoordinates()
            {
                HardpointCoordinates = new PointF(0, 0)
            };

            Assert.AreEqual(5, uc.NearestNHardpoints(5).Count);
        }
Esempio n. 6
0
        public void NearestNHardpoints_N4AtUnambiguousPoint_ReturnsHardpointsInDistanceOrder()
        {
            var uc = new UserCoordinates()
            {
                HardpointCoordinates = new PointF(.6f, .7f)
            };
            var actual = uc.NearestNHardpoints(4);

            Assert.AreEqual(new Hardpoint(1, 1, 0), actual[0]);
            Assert.AreEqual(new Hardpoint(0, 1, 0), actual[1]);
            Assert.AreEqual(new Hardpoint(1, 0, 0), actual[2]);
            Assert.AreEqual(new Hardpoint(0, 0, 0), actual[3]);
        }
Esempio n. 7
0
        public void CaptureUserCoordinates_ShouldWork()
        {
            UserCoordinates userCoordinates = new UserCoordinates();

            string[] coordinates = { "45.7838552", "24.1515281" };

            UserCoordinatesCapture.Capture(userCoordinates, coordinates);

            string actual = userCoordinates.Latitude.ToString() + " " + userCoordinates.Longitude.ToString();

            string expected = "45.7838552 24.1515281";

            Assert.Equal(expected, actual);
        }
Esempio n. 8
0
        public void NearestNHardpoints_N4NearCenterOfGridSquare_ReturnsGridCorners(float x, float y)
        {
            var uc = new UserCoordinates()
            {
                HardpointCoordinates = new PointF(x, y)
            };
            var actual = uc.NearestNHardpoints(4).ToList();

            foreach (var expectedHardpoint in new[]
            {
                new Hardpoint(0, 0, 0),
                new Hardpoint(0, 1, 0),
                new Hardpoint(1, 0, 0),
                new Hardpoint(1, 1, 0)
            })
            {
                Assert.Contains(expectedHardpoint, actual);
            }
        }
Esempio n. 9
0
        public void CoffeeShopDistanceCalculator_ShouldWork()
        {
            UserCoordinates userCoordinates = new UserCoordinates
            {
                Latitude = 45.7838552,

                Longitude = 24.1515281
            };

            List <CoffeeShop> coffeeShopsList = new List <CoffeeShop>()
            {
                new CoffeeShop()
                {
                    Latitude = 45.7826201, Longitude = 24.1465759
                },
                new CoffeeShop()
                {
                    Latitude = 44.4514467, Longitude = 26.0827712
                },
                new CoffeeShop()
                {
                    Latitude = 48.1817174, Longitude = 16.3798455
                }
            };

            CoffeeShopDistanceCalculator.Calculate(userCoordinates, coffeeShopsList);

            List <string> actualCoffeeShopList = new List <string>();

            foreach (var coffeeShop in coffeeShopsList)
            {
                actualCoffeeShopList.Add($"{MathUtilities.RoundValue(coffeeShop.DistanceToUser, 4)}");
            }

            var actual = string.Join(", ", actualCoffeeShopList);

            var expected = "0.408, 211.9753, 646.8313";

            Assert.Equal(expected, actual);
        }
Esempio n. 10
0
        public void NearestNHardpoints_N9AtLocationNearOrigin_ReturnsHardpointsAroundOrigin(float x, float y)
        {
            var uc = new UserCoordinates()
            {
                HardpointCoordinates = new PointF(x, y)
            };
            var actual = uc.NearestNHardpoints(9).ToList();

            foreach (var expectedHardpoint in new[]
            {
                new Hardpoint(-1, -1, 0),
                new Hardpoint(-1, 0, 0),
                new Hardpoint(-1, 1, 0),
                new Hardpoint(0, -1, 0),
                new Hardpoint(0, 0, 0),
                new Hardpoint(0, 1, 0),
                new Hardpoint(1, -1, 0),
                new Hardpoint(1, 0, 0),
                new Hardpoint(1, 1, 0)
            })
            {
                Assert.Contains(expectedHardpoint, actual);
            }
        }