} //CloneTo

            public object Clone()
            {
                MyLocation results = new MyLocation(0, 0);

                this.CloneTo(results);
                return(results);
            } //Clone Function
Example #2
0
        async public Task CheckIfHome(MyLocation HomeLocation, MyLocation CurrentLocation)
        {
            Location Home    = new Location(HomeLocation.lat, HomeLocation.lng);
            Location Current = new Location(CurrentLocation.lat, CurrentLocation.lng);

            lblHomeLocation    = ($"Home: Latitude: {HomeLocation.lat}, Longitude: {HomeLocation.lng}");
            lblCurrentLocation = ($"Current Location: Latitude: {CurrentLocation.lat}, Longitude: {CurrentLocation.lng}");

            //Use the calculate distance method of Location. It returns the distance in kilometers, so it's converted to meters
            //  Then it gets shown on the label/
            double meters = 1000 * Location.CalculateDistance(Home, Current, DistanceUnits.Kilometers);

            lblDistance = "Distance From Home: " + Math.Round(meters).ToString() + " meters";
            if (meters > 100)
            {
                //If the user is more than 100 meters away, we can POST it to the api
                //
                //100 meters is completely arbitrary, it was chosen because I could trigger updates while I walk to work (Tyler)
                //
                //The MyLocation object is serialized into Json using the getters and setters.
                //  The Node side can convert it into a js object when it receives it.
                //
                HttpClient          _client  = new HttpClient();
                string              URL      = "https://www.tylerdoudrick.com/api/coordinates";
                var                 location = CurrentLocation;
                var                 content  = new StringContent(JsonConvert.SerializeObject(location), Encoding.UTF8, "application/json");
                HttpResponseMessage result   = await _client.PostAsync(URL, content);
            }
        }
        public override void PrepareForSegue(UIStoryboardSegue segue, Foundation.NSObject sender)
        {
            base.PrepareForSegue(segue, sender);

            if ("moveToWebViewSegue" == segue.Identifier)
            {
                if (segue.DestinationViewController is MyWebViewController)
                {
                    var destViewController = segue.DestinationViewController as MyWebViewController;

                    destViewController.webUrl = SelectedResturant.Url;
                }
            }

            if ("moveToMapViewSegue" == segue.Identifier)
            {
                if (segue.DestinationViewController is MyMapViewController)
                {
                    var destViewController = segue.DestinationViewController as MyMapViewController;

                    var loc = new MyLocation {
                        Lat = SelectedResturant.Lat, Lng = SelectedResturant.Lng
                    };
                    destViewController.DisplayLocation = loc;
                }
            }
        }
Example #4
0
        async void btnUpdate_Click(object sender, EventArgs e)
        {
            //
            //This button is used to manually update the home location in the event it becomes messed up
            //
            MyLocation myLocation = new MyLocation();

            //Grab the geolocation with 100 meter accuracy and a 3 second timeout
            var request     = new GeolocationRequest(GeolocationAccuracy.Best, new TimeSpan(0, 0, 3));
            var geolocation = await Geolocation.GetLocationAsync(request);

            if (geolocation != null)
            {
                //If we found the location, update the database with the new home location
                //  The database just uses a single row in a single table that contains the home location info
                //  In production, this could store all locations that have been posted to the server

                await Database.DeleteAll();

                myLocation.lat = geolocation.Latitude;
                myLocation.lng = geolocation.Longitude;

                await Database.SaveMyLocationAsync(myLocation);

                //Update the home location label
                lblHomeLocation = ($"Home Location Updated! Latitude: {myLocation.lat}, Longitude: {myLocation.lng}");
            }
        }
        public async Task <ReverseGeocodeResponse> ReverseGeocode(double lat, double lng)
        {
            string result = "";

            using (var client = new HttpClient())
            {
                MyLocation location = new MyLocation();
                location.Lat = lat;
                location.Lng = lng;
                var root = new ReverseGeocodeRequest();
                root.Location = location;

                var settings = new JsonSerializerSettings();
                settings.ContractResolver = new LowercaseSerializer();
                var json = JsonConvert.SerializeObject(root, Formatting.Indented, settings);


                var data     = new StringContent(json, Encoding.UTF8, "application/json");
                var url      = "https://siteapi.cloud.huawei.com/mapApi/v1/siteService/reverseGeocode?key=" + Android.Net.Uri.Encode(ApiKey);
                var response = await client.PostAsync(url, data);

                result = response.Content.ReadAsStringAsync().Result;
            }

            return(JsonConvert.DeserializeObject <ReverseGeocodeResponse>(result));
        }
Example #6
0
        public void Render(IGraphics graphics)
        {
            if (MyLocation != null)
            {
                MyLocation.Render(graphics, ColourPalette.MovementColour);
            }

            if (MyLocation != null && MoveToAbsolute != null)
            {
                new[] { MyLocation, MoveToAbsolute }.Render(graphics, ColourPalette.MovementPen);
            }

            if (MoveToAbsolute != null)
            {
                MoveToAbsolute.Render(graphics, ColourPalette.MovementColour);
            }

            if (Target != null)
            {
                Target.Render(graphics);
            }

            if (MyLocation != null && AimResult != null && AimResult.Location != null)
            {
                new[] { MyLocation, AimResult.Location }.Render(graphics, ColourPalette.AimPen);
            }
        }
Example #7
0
 void checkMyLocation()
 {
     if (myLocation == null)
     {
         myLocation = GameObject.Find("MyLocation").GetComponentInChildren <MyLocation> ();
     }
 }
Example #8
0
        /// <summary>
        /// Updates my location
        /// </summary>
        /// <param name="newLocation">New location</param>
        public void UpdateMyLocation(Position newLocation)
        {
            if (!MyLocation.Equals(newLocation))
            {
                // We have a location update, so abort last animation
                if (mapView.AnimationIsRunning(animationMyLocationName))
                {
                    mapView.AbortAnimation(animationMyLocationName);
                }

                // Save values for new animation
                animationMyLocationStart = MyLocation;
                animationMyLocationEnd   = newLocation;

                var animation = new Animation((v) =>
                {
                    var deltaLat = (animationMyLocationEnd.Latitude - animationMyLocationStart.Latitude) * v;
                    var deltaLon = (animationMyLocationEnd.Longitude - animationMyLocationStart.Longitude) * v;
                    var modified = InternalUpdateMyLocation(new Position(animationMyLocationStart.Latitude + deltaLat, animationMyLocationStart.Longitude + deltaLon));
                    // Update viewport
                    if (modified && mapView.MyLocationFollow && mapView.MyLocationEnabled)
                    {
                        mapView._mapControl.Navigator.CenterOn(MyLocation.ToMapsui());
                    }
                    // Refresh map
                    if (mapView.MyLocationEnabled && modified)
                    {
                        mapView.Refresh();
                    }
                }, 0.0, 1.0);

                // At the end, update viewport
                animation.Commit(mapView, animationMyLocationName, 100, 3000, finished: (s, v) => mapView.Map.RefreshData(mapView._mapControl.Viewport.Extent, mapView._mapControl.Viewport.Resolution, true));
            }
        }
Example #9
0
        // int _pinCreatedCount = 0;



        async Task <MyLocation> IDatabase.GetCurrentLocation()
        {
            var noLocation = new MyLocation();

            try {
                var loc = await Xamarin.Essentials.Geolocation.GetLocationAsync();

                var pins = await Geocoding.GetPlacemarksAsync(loc.Latitude, loc.Longitude);

                var firstPin = pins.FirstOrDefault();

                var myLocation = new MyLocation()
                {
                    Address     = firstPin.SubLocality,
                    Description = firstPin.FeatureName,
                    Latitude    = loc.Latitude,
                    Longitude   = loc.Longitude
                };

                return(myLocation);
            }
            catch (FeatureNotEnabledException ex)
            {
                await _pageDialogService.DisplayAlertAsync("Exception", "Please turn on your GPS location", "Ok");

                return(noLocation);
            }

            //return new MyLocation(firstPin.SubLocality, firstPin.FeatureName, new Xamarin.Forms.Maps.Position(loc.Latitude, loc.Longitude));
        }
Example #10
0
 void checkMyLocation()
 {
     /* TODO: This needs to be completed */
     if (myLocation == null)
     {
         myLocation = GameObject.Find("MyLocation").GetComponentInChildren <MyLocation>();
     }
 }
Example #11
0
        public void GetLocationTest()
        {
            MyLocation location = viewModel.Model.GetLocation(102);

            Assert.AreEqual(location.Name, "Location2");
            Assert.AreEqual(location.CostRate, new decimal(12.35));
            Assert.AreEqual(location.Availability, new decimal(12.35));
        }
Example #12
0
            } //CloneTo

            public void CloneTo(MyLocation item)
            {
                if (item == null)
                {
                    return;
                }
                item.X = this.X;
                item.Y = this.Y;
            } //CloneTo
Example #13
0
            public override bool Equals(object obj)
            {
                if (obj == null || !(obj is MyLocation))
                {
                    return(false);
                }
                MyLocation b = (MyLocation)obj;

                return(this.X == b.X && this.Y == b.Y);
            } //Equals
Example #14
0
        public MapProcessor()
        {
            InitializeComponent();
            MyLocation currentLocation = CoordinateProcessor.GetUserCoordinates();

            this.userX = currentLocation.Data.Lat;
            this.userY = currentLocation.Data.Lon;

            List <Institutions> dataFromBarDataBase = CoordinateProcessor.DeserializeJsonFile();

            this.barCoordinates = CoordinateProcessor.GetBarPoints(dataFromBarDataBase);
        }
Example #15
0
            } //New

            public double GetDistance(BaseLocation target)
            {
                if (target == null || !(target is MyLocation))
                {
                    return(double.MaxValue);
                }
                MyLocation targetLoc = (MyLocation)target;
                int        dx        = (this.X - targetLoc.X);
                int        dy        = (this.Y - targetLoc.Y);

                return(System.Math.Sqrt(dx * dx + dy * dy));
            } //GetDistance
Example #16
0
            } //GetDistance

            public double GetHeuristicDistance(BaseLocation target)
            {
                if (target == null || !(target is MyLocation))
                {
                    return(double.MaxValue);
                }
                MyLocation targetLoc = (MyLocation)target;
                double     cons      = 1.2;
                double     result    = cons * System.Math.Abs(this.X - targetLoc.X);

                result += cons * System.Math.Abs(this.Y - targetLoc.Y);
                return(result);
            } //GetHeuristicDistance
Example #17
0
            public void CloneTo(BaseLocation item)
            {
                if (item == null)
                {
                    return;
                }

                if (item is MyLocation)
                {
                    MyLocation locItem = (MyLocation)item;
                    this.CloneTo(locItem);
                }
            } //CloneTo
Example #18
0
        /// <summary>
        /// Finds the nearest matching route
        /// </summary>
        /// <param name="routeName">Name of route</param>
        /// <returns></returns>
        private static async Task <BusRoute> GetNearestMatchingRoute(string routeName)
        {
            BusRoute retRoute = null;

            if (RouteIDs.ContainsKey(routeName))
            {
                if (RouteIDs[routeName].Count == 0)
                {
                    return(null);
                }
                if (RouteIDs[routeName].Count == 1)
                {
                    if (!AppSettings.KnownRoutes.Value.ContainsKey(RouteIDs[routeName][0]))
                    {
                        return(null);
                    }
                    retRoute = await TransitLoader.GetRoute(RouteIDs[routeName][0]);

                    return(retRoute);
                }

                double minDist = double.PositiveInfinity;
                foreach (string id in RouteIDs[routeName])
                {
                    if (!AppSettings.KnownRoutes.Value.ContainsKey(id))
                    {
                        return(retRoute);
                    }
                    var br = AppSettings.KnownRoutes.Value[id];
                    if (br.Stop_Ids == null || br.Stop_Ids.Count == 0)
                    {
                        return(retRoute);
                    }

                    BusStop firststop = await TransitLoader.GetStop(br.Stop_Ids[0]);

                    if (firststop == null)
                    {
                        continue;
                    }
                    var dist = MyLocation.GetDistanceTo(firststop.Location);
                    if (minDist > dist)
                    {
                        retRoute = br;
                        minDist  = dist;
                    }
                }
                return(retRoute);
            }
            return(null);
        }
Example #19
0
        //private FlightViewModel flightViewModel;

        public MainWindow()
        {
            InitializeComponent();
            flightModel = new IFlightModel(new TcpTimeClient(10000));
            FlightViewModel flightViewModel = new FlightViewModel(flightModel);
            MapViewModel    mapViewModel    = new MapViewModel(flightModel);

            MySetteing.SetDataContext(flightViewModel);
            MyDashBoard.SetDataContext(flightViewModel);
            MyPrideBoard.SetDataContext(flightModel);
            MyMap.SetDataContext(mapViewModel);
            MyLocation.SetDataContext(mapViewModel);
            //MyExitButton.SetDataContext(flightViewModel);
        }
Example #20
0
        //GEO LOCATION STATS
        public static void GeoStats(string linkVal)
        {
            string [] linkVals = linkVal.Trim().Split(new char [] { ',' });
            if (linkVals.Length > 0)
            {
                // RUN GEOLOCATION
                foreach (var ppl in linkVals)
                {
                    Task.WaitAll(AmplifiGeoStart.Run(ppl.Trim()));
                    AmplifiGeoMetadata data = AmplifiGeoStart.GeoReport();

                    InnerAddr indr = new InnerAddr();
                    foreach (var d in data.results)
                    {
                        if (d != null)
                        {
                            foreach (var dd in d.address_components)
                            {
                                indr = dd;
                                //CHECK BEFORE CALL VALUES
                                if (indr.types.Contains("town"))
                                {
                                    Console.WriteLine("City: {0}", indr.long_name);
                                }
                                if (indr.types.Contains("locality"))
                                {
                                    Console.WriteLine("Area: {0}", indr.long_name);
                                }
                                if (indr.types.Contains("administrative_area_level_2"))
                                {
                                    Console.WriteLine("County : {0}", indr.long_name);
                                }
                                if (indr.types.Contains("administrative_area_level_1"))
                                {
                                    Console.WriteLine("State : {0}", indr.long_name);
                                }
                                if (indr.types.Contains("country"))
                                {
                                    Console.WriteLine("Country : {0}", indr.long_name);
                                }
                            }
                            //CALL LOCATION LAT AND LNG
                            MyLocation location = d.geometry.location;
                            Console.WriteLine("LNG: {0}\nLAT: {1}", location.lng, location.lat);
                            Console.WriteLine();
                        }
                    }
                }
            }
        }
Example #21
0
            internal override List <BaseLocation> GetAdjacentLocations(BaseLocation location)
            {
                if (location == null || !(location is MyLocation))
                {
                    return(null);
                }
                MyLocation myLocation = (MyLocation)location;

                List <BaseLocation> result = new List <BaseLocation>();

                result.Add(new MyLocation(myLocation.X - 1, myLocation.Y));
                result.Add(new MyLocation(myLocation.X + 1, myLocation.Y));
                result.Add(new MyLocation(myLocation.X, myLocation.Y - 1));
                result.Add(new MyLocation(myLocation.X, myLocation.Y + 1));
                return(result);
            } //GetAdjacentLocations
Example #22
0
        protected override async void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.Main);
            CrossCurrentActivity.Current.Init(this, savedInstanceState);
            _location = new MyLocation(SetLocation);
            await _location.StartListening();

            FindViewById();

            SetEventHandlers();
            SetDeviceInfo();

            await GetLocation();
        }
Example #23
0
 private async void OnLocationUpdates(object sender, Location location)
 {
     //Hover on customized "CompareTo" to see how two locations compared.
     if ((MyLocation == null) || (MyLocation.CompareTo(location) != 0))
     {
         Device.BeginInvokeOnMainThread(() =>
         {
             MyLocation = location;
         });
         if (ServerCommunicator.Instance.GroupID != null)
         {
             //TODO: why SendLocationAsync(MyLocation) throwing exception
             await ServerCommunicator.Instance.SendLocationAsync(location);
         }
     }
 }
Example #24
0
        public async Task <MyLocation> CheckHomeSet()
        {
            //Attempt to grab the location record from the database
            List <MyLocation> location = new List <MyLocation>();

            location = await Database.GetMyLocationsAsync();

            if (location.Count == 0)
            {
                //If the location isn't saved, ask the user if they are home
                bool answer = await DisplayAlert("Home not saved!", "Are you at home? We need to save your home location", "Yes", "No");

                if (answer)
                {
                    //If they're home, grab the location from the geolocator and save it in the database record
                    MyLocation myLocation  = new MyLocation();
                    var        request     = new GeolocationRequest(GeolocationAccuracy.Best, new TimeSpan(0, 0, 3));
                    var        geolocation = await Geolocation.GetLocationAsync(request);

                    if (geolocation != null)
                    {
                        myLocation.lat = geolocation.Latitude;
                        myLocation.lng = geolocation.Longitude;
                        await Database.SaveMyLocationAsync(myLocation);

                        return(myLocation);
                    }
                }
                else
                {
                    //If they aren't home, do nothing
                    //
                    //Ideally, this would close the application so that the user could open it when they are home
                    //
                    //  A push notification would assist in that
                    return(null);
                }
            }
            else
            {
                //If the home location is stored already, return it.
                await DisplayAlert("Found home", "Home location already stored!", "OK");

                return(location[0]);
            }
            return(null);
        }
Example #25
0
            } //GetAdjacentLocations

            internal override bool IsLocationValid(BaseLocation location)
            {
                if (location == null || !(location is MyLocation))
                {
                    return(false);
                }
                MyLocation myLocation = (MyLocation)location;

                if (myLocation.X >= 1 && myLocation.Y >= 1 && myLocation.X <= this.Map.Width && myLocation.Y <= this.Map.Height)
                {
                    return(!this.Map.Item[myLocation.X - 1, myLocation.Y - 1]);
                }
                else
                {
                    return(false);
                }
            } //IsLocationValid
Example #26
0
        public async Task <MyLocation> GetCurrentLocation()
        {
            //Wait for the current location from Geolocator and set return it as a MyLocation type
            MyLocation myLocation  = new MyLocation();
            var        request     = new GeolocationRequest(GeolocationAccuracy.Best, new TimeSpan(0, 0, 5));
            var        geolocation = await Geolocation.GetLocationAsync(request);

            if (geolocation != null)
            {
                myLocation.lat = geolocation.Latitude;
                myLocation.lng = geolocation.Longitude;

                return(myLocation);
            }

            return(null);
        }
Example #27
0
 public void saveGame()
 {
     try
     {
         //wrap this in try catch for better experiences.
         //save a file
         StreamWriter sw = new StreamWriter("C:\\Users\\Steve\\Source\\Repos\\OurTextBasedAdventure\\Resources\\Player.txt");
         sw.WriteLine(MyLocation.getRoomIndicator());
         sw.Flush();
         sw.Close();
         sw.Dispose();
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Example #28
0
 public LevelMap(string composition)
 {
     if (composition == "comp1")
     {
         locations = new MyLocation[gridSize, gridSize];
         //pretty random level 1;
         locations[0, 0] = new MyLocation("Pool1-Monster-4way", up: false, down: false, left: false, right: true);
         locations[1, 0] = new MyLocation("Pool1-Monster-4way", up: false, down: false, left: false, right: true);
         locations[2, 0] = new MyLocation("Pool1-Monster-4way", up: false, down: false, left: false, right: true);
         locations[2, 1] = new MyLocation("Pool1-Monster-4way", up: false, down: false, left: false, right: true);
         locations[3, 1] = new MyLocation("Pool1-Monster-4way", up: false, down: false, left: false, right: true);
         locations[4, 1] = new MyLocation("Pool1-Monster-4way", up: false, down: false, left: false, right: true);
         locations[3, 0] = new MyLocation("Pool1-Monster-4way", up: false, down: false, left: false, right: true);
         locations[3, 2] = new MyLocation("Pool1-Monster-4way", up: false, down: false, left: false, right: true);//reward room?
         locations[3, 3] = new MyLocation("Pool1-Monster-4way", up: false, down: false, left: false, right: true);
         locations[5, 1] = new MyLocation("sceneBoss1", up: false, down: false, left: false, right: true);
         locations[6, 1] = new MyLocation("sceneShop1", up: false, down: false, left: false, right: true);
     }
 }
Example #29
0
        async void btnChangeLocation_Click(object sender, EventArgs e)
        {
            //
            //This is a button that was used specifically for development
            //
            //Due to Philadelphia's measures on sheltering in place, testing the application is difficult
            //  This button allows data to be entered manually.
            //
            MyLocation CurrentLocation = new MyLocation();
            MyLocation HomeLocation    = new MyLocation();

            CurrentLocation.lat = 39.973122;
            CurrentLocation.lng = -75.116068;


            HomeLocation = await CheckHomeSet();

            await CheckIfHome(HomeLocation, CurrentLocation);
        }
        private void UpdateMap(Plugin.Geolocator.Abstractions.Position position)
        {
            try
            {
                var gFormsPos = new Xamarin.Forms.GoogleMaps.Position(position.Latitude, position.Longitude);
                MyLocation.Clear();
                MyLocation.Add(new Pin()
                {
                    Position = gFormsPos,
                    Label    = "My Position"
                });


                MoveToRegionRequest.MoveToRegion(MapSpan.FromCenterAndRadius(gFormsPos,
                                                                             Distance.FromKilometers(1)));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
 void checkMyLocation()
 {
     /* TODO: This needs to be completed */
     if (myLocation == null)
         myLocation = GameObject.Find("MyLocation").GetComponentInChildren<MyLocation>();
 }
Example #32
0
 void checkMyLocation()
 {
     //Idk if this works
     if(myLocation == null)
     {
         myLocation = GameObject.Find ("MyLocation").GetComponentInChildren<MyLocation>();
     }
 }