Exemple #1
0
        //Methode om de data van de diefstallen en bikecontainers op te halen.
        public async Task LoadData()
        {
            vm      = new BikeContainerViewModel();
            theftVM = new BikeTheftViewModel();
            await vm.GetHaltesAsync();

            await theftVM.GetBikeTheftsAsync();

            containers = vm.BikeContainers;
            thefts     = theftVM.BikeThefts;
        }
        //async methode om neighbourhoods met containers te genereren.
        public async Task <BikeGraphModel> GenerateNeighbourhoods()
        {
            //Een nieuwe bikegraphmodel aanmaken die gebruikt wordt om data in de grafiek te zetten
            BikeGraphModel         bgm = new BikeGraphModel();
            BikeContainerViewModel vm  = new BikeContainerViewModel();
            await vm.GetHaltesAsync();

            ObservableCollection <BikeContainer> containers = vm.BikeContainers;

            foreach (BikeContainer container in containers)
            {
                //Als er een unieke neighbourhood naam is gevonden wordt deze aan de hashset toegevoegd
                if (neighbourhoods.Add(container.Neighbourhood))
                {
                    Neighbourhood neighb = new Neighbourhood();
                    neighb.Name = container.Neighbourhood;
                    realNeighbourhoods.Add(neighb);
                }

                //Hier wordt de bikecontainer toegevoegd aan de bijbehorende neighbourhood
                Neighbourhood nb = realNeighbourhoods.Find(x => x.Name.Contains(container.Neighbourhood));
                nb.AddContainer(container);
            }

            //De top 5 selecteren van de neighbourhoods.
            var r = realNeighbourhoods.OrderByDescending(x => x.BikeContainerCount).Take(5);

            //Door de top 5 loopen en toevoegen aan het model.
            foreach (Neighbourhood nb in r)
            {
                //Naam afkorten anders past deze niet op de grafiek.
                if (nb.Name.Length > 10)
                {
                    nb.Name = nb.Name.Substring(0, 10);
                }
                bgm.AddData(nb);
            }

            return(bgm);
        }
Exemple #3
0
        public async void GenerateList()
        {
            try
            {
                BikeContainerViewModel bikeContainerViewModel = new BikeContainerViewModel();
                await bikeContainerViewModel.GetHaltesAsync();

                var containers = bikeContainerViewModel.BikeContainers;
                var locator    = CrossGeolocator.Current;
                locator.DesiredAccuracy = 50;

                var tempPos = await locator.GetPositionAsync(timeoutMilliseconds : 10000);

                myPosition = new Position(tempPos.Latitude, tempPos.Longitude);


                var fcontainers = ClosestTo(containers, myPosition);


                // Create the ListView.
                listView = new ListView
                {
                    // Source of data items.
                    ItemsSource = fcontainers,

                    // Define template for displaying each item.
                    // (Argument of DataTemplate constructor is called for
                    //      each item; it must return a Cell derivative.)
                    ItemTemplate = new DataTemplate(() =>
                    {
                        // Create views with bindings for displaying each property.
                        Label nameLabel = new Label();
                        nameLabel.SetBinding(Label.TextProperty, "Street");

                        Label birthdayLabel = new Label();
                        Binding lat         = new Binding();

                        birthdayLabel.SetBinding(Label.TextProperty, "Distance");
                        birthdayLabel.SetBinding(Label.TextProperty,
                                                 new Binding("Distance", BindingMode.OneWay,
                                                             null, null, "{0} Meter"));
                        //BoxView boxView = new BoxView();
                        //boxView.SetBinding(BoxView.ColorProperty, "FavoriteColor");

                        // Return an assembled ViewCell.
                        return(new ViewCell
                        {
                            View = new StackLayout
                            {
                                Padding = new Thickness(0, 5),
                                Orientation = StackOrientation.Horizontal,
                                Children =
                                {
                                    //boxView,
                                    new StackLayout
                                    {
                                        VerticalOptions = LayoutOptions.Center,
                                        Spacing = 0,
                                        Children =
                                        {
                                            nameLabel,
                                            birthdayLabel
                                        }
                                    }
                                }
                            }
                        });
                    })
                };

                map = new CustomMap(
                    MapSpan.FromCenterAndRadius(
                        new Position(51.9202975795699, 4.49352622032165), Distance.FromMiles(5)))
                {
                    IsShowingUser = true,
                    HeightRequest = 200,
                    WidthRequest  = 320,
                    MapType       = MapType.Hybrid,
                };


                foreach (var container in containers)
                {
                    var position = new Position(container.Latitude, container.Longitude);
                    var pin      = new Pin
                    {
                        Type     = PinType.Place,
                        Position = position,
                        Label    = container.Description,
                        Address  = container.Street
                    };
                    map.Pins.Add(pin);
                }


                var pin2 = new Pin
                {
                    Type     = PinType.Place,
                    Position = myPosition,
                    Label    = "me"
                };
                map.Pins.Add(pin2);

                DoubleClick doubleClick = new DoubleClick();

                listView.ItemTapped += async(object sender, ItemTappedEventArgs e) =>
                {
                    BikeContainer container = e.Item as BikeContainer;
                    //var selectedContainer = container;
                    var containerPosition = new Position(container.Latitude, container.Longitude);


                    if (doubleClick.Check(container))
                    {
                        geoCoder = new Geocoder();
                        var possibleAddresses = await geoCoder.GetAddressesForPositionAsync(containerPosition);

                        string containeraddress = "";
                        foreach (var address in possibleAddresses)
                        {
                            containeraddress = address;
                        }

                        switch (Device.OS)
                        {
                        case TargetPlatform.iOS:
                            Device.OpenUri(
                                new Uri(string.Format("http://maps.apple.com/?q={0}", WebUtility.UrlEncode(containeraddress))));
                            break;

                        case TargetPlatform.Android:
                            Device.OpenUri(
                                new Uri(string.Format("geo:0,0?q={0}", WebUtility.UrlEncode(containeraddress))));
                            break;
                        }
                    }
                    else
                    {
                        //var containerPosition = new Position(container.Latitude, container.Longitude);
                        map.MoveToRegion(
                            MapSpan.FromCenterAndRadius(
                                containerPosition, Distance.FromMiles(.1f)));
                    }
                };

                var stack = new StackLayout {
                    Spacing = 0
                };
                var innerStack = new StackLayout {
                    Spacing = 0
                };
                Button gotoMyLocation = new Button {
                    Text = "My location"
                };
                gotoMyLocation.Clicked += gotoMyLocation_clicked;
                innerStack.Children.Add(map);
                stack.Children.Add(new Label {
                    Text = "Map"
                });

                // Accomodate iPhone status bar.
                this.Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5);

                stack.Children.Add(innerStack);
                stack.Children.Add(gotoMyLocation);
                stack.Children.Add(listView);
                Content = stack;
            }
            catch
            {
                Label locationLabel;
                locationLabel = new Label
                {
                    Text = "No GPS available, please restart the app and try again with GPS enabled.",
                    Font = Font.SystemFontOfSize(NamedSize.Large),
                    HorizontalOptions = LayoutOptions.Center,
                    VerticalOptions   = LayoutOptions.CenterAndExpand
                };
                Content = new StackLayout
                {
                    Children =
                    {
                        locationLabel
                    }
                };
                await DisplayAlert("No GPS available", "We could not retrieve your location on time, please try again.", "OK");
            }
        }