コード例 #1
0
ファイル: MainPage.xaml.cs プロジェクト: rvnijnatten/WeBreda
        /// <summary>
        /// Create the page
        /// </summary>
        public MainPage()
        {
            this.InitializeComponent();
            
            //Enable page cache for this page
            this.NavigationCacheMode = Windows.UI.Xaml.Navigation.NavigationCacheMode.Enabled;

            routeCalculated = false;
            locatorReady = false;
            positionSet = false;
            started = false;
            popupClosing = false;
            locationIcon10m = new LocationIcon10m();
            Map.Children.Add(locationIcon10m);
            setupGeolocator();
            setupDirectionsmanager();
            Version.Text = typeof(MainPage).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyFileVersionAttribute>().Version;
        }
コード例 #2
0
        private async Task Relocation()
        {
            LocationGrid.Visibility = Visibility.Visible;

            _geolocator       = new Geolocator();
            _locationIcon10m  = new LocationIcon10m();
            _locationIcon100m = new LocationIcon100m();

            // Remove any previous location icon.
            if (map.Children.Count > 0)
            {
                map.Children.RemoveAt(0);
            }

            try
            {
                // Get the cancellation token.
                _cts = new CancellationTokenSource();
                CancellationToken token = _cts.Token;

                //MessageTextbox.Text = "Waiting for update...";

                // Get the location.
                Geoposition pos = await _geolocator.GetGeopositionAsync().AsTask(token);

                //MessageTextbox.Text = "";

                Location location = new Location(pos.Coordinate.Latitude, pos.Coordinate.Longitude);

                // Now set the zoom level of the map based on the accuracy of our location data.
                // Default to IP level accuracy. We only show the region at this level - No icon is displayed.
                double zoomLevel = 13.0f;

                // if we have GPS level accuracy
                if (pos.Coordinate.Accuracy <= 10)
                {
                    // Add the 10m icon and zoom closer.
                    map.Children.Add(_locationIcon10m);
                    MapLayer.SetPosition(_locationIcon10m, location);
                    zoomLevel = 15.0f;
                }
                // Else if we have Wi-Fi level accuracy.
                else
                //if (pos.Coordinate.Accuracy <= 100)
                {
                    // Add the 100m icon and zoom a little closer.
                    map.Children.Add(_locationIcon100m);
                    MapLayer.SetPosition(_locationIcon100m, location);
                    zoomLevel = 14.0f;
                }

                // Set the map to the given location and zoom level.
                map.SetView(location, zoomLevel);

                // Display the location information in the textboxes.
                //LatitudeTextbox.Text = pos.Coordinate.Latitude.ToString();
                //LongitudeTextbox.Text = pos.Coordinate.Longitude.ToString();
                //AccuracyTextbox.Text = pos.Coordinate.Accuracy.ToString();
            }
            catch (System.UnauthorizedAccessException)
            {
                //MessageTextbox.Text = "Location disabled.";

                //LatitudeTextbox.Text = "No data";
                //LongitudeTextbox.Text = "No data";
                //AccuracyTextbox.Text = "No data";
            }
            catch (TaskCanceledException)
            {
                //MessageTextbox.Text = "Operation canceled.";
            }
            finally
            {
                _cts = null;
            }

            // Reset the buttons.
            //MapLocationButton.IsEnabled = true;
            //CancelGetLocationButton.IsEnabled = false;

            LocationGrid.Visibility = Visibility.Collapsed;
        }