Esempio n. 1
0
        public MapPage()
        {
            InitializeComponent();


            _restService = new Trkr.RestServices.RestService();

            // 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;
        }
Esempio n. 2
0
        static async void TrackingLoop()
        {
            Trkr.RestServices.RestService _restService;
            _restService = new Trkr.RestServices.RestService();

            CustomMap iCustomMap   = new CustomMap();
            CustomMap havetoListTo = 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.locationAdress), locationParameter);

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

                        havetoListTo.RouteCoordinates.Add(new Position(locationParameter.Latitude, locationParameter.Longitude));
                    }
                }

                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);
            }
        }
Esempio n. 3
0
 public LoginPage()
 {
     InitializeComponent();
     _restService = new Trkr.RestServices.RestService();
 }