Exemplo n.º 1
0
        //CustomMap iCustomMap =  new CustomMap();

        public Maps()
        {
            // Da initzialisiere ich den aufder der Seite
            InitializeComponent();
            _restService = new Tracker.RestService.RestService();
            // testing maps
            //SaveCurrentLocation();

            // create Map to view!
            var map = new Xamarin.Forms.Maps.Map(
                MapSpan.FromCenterAndRadius(
                    // ZHAW Winterthur 47.496848 / 8.729818
                    new Position(47.496848, 8.729818), Distance.FromKilometers(0.45)))
            {
                IsShowingUser = true,
                // note sure if Height and WidthRequest is necessary
                HeightRequest   = 100,
                WidthRequest    = 960,
                VerticalOptions = LayoutOptions.FillAndExpand
            };

            if (IsLocationAvailable())
            {
                GetPosition();
                //map.MoveToRegion(MapSpan.FromCenterAndRadius(_position, Distance.FromKilometers(0.45)));
            }

            map.MapType = MapType.Street;
            var stack = new StackLayout {
                Spacing = 0
            };

            stack.Children.Add(map);
            Content = stack;
        }
Exemplo n.º 2
0
        static async void TrackingLoop()
        {
            Tracker.RestService.RestService _restService;
            _restService = new Tracker.RestService.RestService();

            CustomMap iCustomMap = new CustomMap();

            while (true)
            {
                LocationData locationParameter = null;


                try
                {
                    var      request  = new GeolocationRequest(GeolocationAccuracy.Best);
                    Location location = await Geolocation.GetLocationAsync(request);

                    if (location != null)
                    {
                        Console.WriteLine($"Latitude: {location.Latitude}, Longitude: {location.Longitude}, Altitude: {location.Altitude}");
                        locationParameter = new LocationData
                        {
                            Guid      = Guid.NewGuid(),
                            Latitude  = location.Latitude,
                            Longitude = location.Longitude,
                            Velocity  = (double)location.Speed,
                            Timestamp = DateTime.Now.ToString(),
                            UserId    = App.logedInUser.Email
                        };
                    }


                    // chechs if i moving faster than 1 m/s^
                    if (locationParameter.Velocity > 1)
                    {
                        LocationData locationData = await _restService.CreateLocation(GenerateLocationUri(Constants.createPosition), locationParameter);

                        iCustomMap.RouteCoordinates.Add(new Position(locationParameter.Latitude, locationParameter.Longitude));
                        iCustomMap.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(locationParameter.Latitude, locationParameter.Longitude), Distance.FromKilometers(1.5)));
                    }
                }

                catch (FeatureNotSupportedException fnsEx)
                {
                    // Handle not supported on device exception
                }
                catch (FeatureNotEnabledException fneEx)
                {
                    // Handle not enabled on device exception
                }
                catch (PermissionException pEx)
                {
                    // Handle permission exception
                }
                catch (Exception ex)
                {
                    // Unable to get location
                }

                await Task.Delay(10000);
            }


            string GenerateLocationUri(string endpoint)
            {
                string requestUri = endpoint;

                requestUri += $"?apiKey={Constants.APIKey}";

                return(requestUri);
            }
        }
Exemplo n.º 3
0
 public Login()
 {
     InitializeComponent();
     _restService = new Tracker.RestService.RestService();
 }