private async void ShowThisLocationAsync(object sender, RoutedEventArgs e)
        {
            var accesStatus = await Geolocator.RequestAccessAsync();

            switch (accesStatus)
            {
            case GeolocationAccessStatus.Allowed:

                //Here we get the user's position using C++
                var cPlusPlusClass = new CppProj.Class1();
                var position       = await cPlusPlusClass.ReturnPosition();

                Geopoint thisLocation = position.Coordinate.Point;

                double lat   = thisLocation.Position.Latitude;
                double lon   = thisLocation.Position.Longitude;
                double speed = (double)position.Coordinate.Speed;

                if (double.IsNaN(speed))
                {
                    speed = 0.0;
                }

                AddMarkerUserPos(thisLocation, "Lat: " + lat.ToString() +
                                 "\n" + " Long: " + lon.ToString() +
                                 "\n" + "Speed: " + speed.ToString());

                MapControl1.Center           = thisLocation;
                MapControl1.ZoomLevel        = 17;
                MapControl1.LandmarksVisible = true;

                Converters converter = new Converters();

                CheckpointsClient checkPoint = new CheckpointsClient
                {
                    RouteID    = routeId.ToString(),
                    Latitude   = converter.FromDoubleToString(lat),
                    Longitude  = converter.FromDoubleToString(lon),
                    CPDateTime = DateTime.Now
                };

                RequestHandler handler = new RequestHandler();
                await handler.PostDataToAPI(checkPoint);

                break;

            case GeolocationAccessStatus.Denied:
                break;

            case GeolocationAccessStatus.Unspecified:
                break;
            }
        }
Example #2
0
        public async Task PostDataToAPI(CheckpointsClient checkpointToPost)
        {
            using (var client = RouteHttpClient.GetRequest())
            {
                StringContent       content  = new StringContent(JsonConvert.SerializeObject(checkpointToPost), Encoding.UTF8, "application/json");
                HttpResponseMessage response = await client.PostAsync("api/Checkpoints", content);

                if (!response.IsSuccessStatusCode)
                {
                    throw new Exception((int)response.StatusCode + "-" + response.StatusCode.ToString());
                }
            }
        }
        private async void UpdatePosition()
        {
            var accesStatus = await Geolocator.RequestAccessAsync();

            switch (accesStatus)
            {
            case GeolocationAccessStatus.Allowed:

                Geolocator  geolocator = new Geolocator();
                Geoposition position   = await geolocator.GetGeopositionAsync();

                Geopoint thisLocation = position.Coordinate.Point;

                path.Add(thisLocation);

                double lat = thisLocation.Position.Latitude;
                double lon = thisLocation.Position.Longitude;

                ShowPath();

                Converters converter = new Converters();

                CheckpointsClient checkPoint = new CheckpointsClient
                {
                    RouteID    = routeId.ToString(),
                    Latitude   = converter.FromDoubleToString(lat),
                    Longitude  = converter.FromDoubleToString(lon),
                    CPDateTime = DateTime.Now
                };

                RequestHandler handler = new RequestHandler();
                await handler.PostDataToAPI(checkPoint);

                break;

            case GeolocationAccessStatus.Denied:
                break;

            case GeolocationAccessStatus.Unspecified:
                break;
            }
        }
Example #4
0
        public double ComputeSpeed(CheckpointsClient cp1, CheckpointsClient cp2)
        {
            var pos1 = new BasicGeoposition()
            {
                Latitude  = Convert.ToDouble(cp1.Latitude),
                Longitude = Convert.ToDouble(cp1.Longitude)
            };
            var pos2 = new BasicGeoposition()
            {
                Latitude  = Convert.ToDouble(cp2.Latitude),
                Longitude = Convert.ToDouble(cp2.Longitude)
            };
            double R    = 6371;
            double dLat = ToRadian(pos2.Latitude - pos1.Latitude);
            double dLon = ToRadian(pos2.Longitude - pos1.Longitude);
            double a    = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) +
                          Math.Cos(this.ToRadian(pos1.Latitude)) * Math.Cos(this.ToRadian(pos2.Latitude)) *
                          Math.Sin(dLon / 2) * Math.Sin(dLon / 2);
            double c = 2 * Math.Asin(Math.Min(1, Math.Sqrt(a)));
            double d = (R * c) * 1000;

            return(d / Math.Abs(((cp1.CPDateTime.Second + cp1.CPDateTime.Minute * 60 + cp1.CPDateTime.Hour * 3600) -
                                 (cp2.CPDateTime.Second + cp2.CPDateTime.Minute * 60 + cp2.CPDateTime.Hour * 3600))));
        }