コード例 #1
0
ファイル: MainPage.xaml.cs プロジェクト: winappkits/TomTomAPI
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            // Navigate to new destination
            if (e.NavigationMode == NavigationMode.New)
            {
                LatLong destination;
                LatLong.TryParse(e.Parameter as String, out destination);

                GotoLocation(destination, showMessage: !_firstRun);
            }
            else
            {
                // refresh the point-of-interest list given coordinates saved in page state.  Note that Refresh is async, but
                // we are not awaiting it to lessen risk that a resume operation will timeout
                if (_pageState.MapBox != null)
                {
                    LeftPanel.Refresh(_pageState.MapBox, _pageState.SelectedItemId);
                }

                // reset map to last known view
                TheMap.SetView(new Location(_pageState.MapCenter.Latitude, _pageState.MapCenter.Longitude), _pageState.Zoom, MapAnimationDuration.None);
            }

            DataTransferManager dtm = DataTransferManager.GetForCurrentView();

            dtm.DataRequested += LeftPanel.GetSharedData;
        }
コード例 #2
0
ファイル: MainPage.xaml.cs プロジェクト: jimoneil/TrafficCams
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            // initialize orientation (used later when determine if map view requires update)
            _priorOrientation = ApplicationView.Value;

            // register data callback for sharing
            var dtm = DataTransferManager.GetForCurrentView();

            dtm.DataRequested += LeftPanel.GetSharedData;

            // Navigate to new destination
            if (e.NavigationMode == NavigationMode.New)
            {
                LatLong destination;
                LatLong.TryParse(e.Parameter as String, out destination);

                GotoLocation(destination, showMessage: !_firstRun);
            }
            else
            {
                // refresh the point-of-interest list given coordinates saved in page state.  Note that Refresh is async, but
                // we are not awaiting it to lessen risk that a resume operation will timeout
                if (_pageState.MapBox != null)
                {
                    LeftPanel.Refresh(_pageState.MapBox, _pageState.SelectedItemId);
                }

                // reset map to last known view
                _retainRefreshRequiredViewChange = true;
                TheMap.SetView(new Location(_pageState.MapCenter.Latitude, _pageState.MapCenter.Longitude), _pageState.Zoom, MapAnimationDuration.None);
            }
        }
コード例 #3
0
ファイル: MainPage.xaml.cs プロジェクト: jimoneil/TrafficCams
        /// <summary>
        /// Navigates map centering on given location
        /// </summary>
        /// <param name="position">Latitude/longitude point of new location (if null, current location is detected via GPS)</param>
        /// <param name="showMessage">Whether to show message informing user that location tracking is not enabled on device.</param>
        async Task GotoLocation(LatLong position, Boolean showMessage = false)
        {
            Boolean currentLocationRequested = position == null;

            // a null location is the cue to use geopositioning
            if (currentLocationRequested)
            {
                try
                {
                    _geolocator = new Geolocator();

                    // register callback to reset (hide) the user's location, if location access is revoked while app is running
                    _geolocator.StatusChanged += (s, a) =>
                    {
                        this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
                                                 new Windows.UI.Core.DispatchedHandler(() =>
                        {
                            if (a.Status == PositionStatus.Disabled)
                            {
                                _locationMarker.Visibility = Visibility.Collapsed;
                            }
                        })
                                                 );
                    };

                    Geoposition currentPosition = await _geolocator.GetGeopositionAsync();

                    position = new LatLong(currentPosition.Coordinate.Latitude, currentPosition.Coordinate.Longitude);
                }
                catch (Exception)
                {
                    // edge case for initial appearance of map when location services are turned off
                    App.InitialMapResizeHasOccurred = true;

                    if (showMessage)
                    {
                        MessageDialog md =
                            new MessageDialog("This application is unable to determine your current location; however, you can continue to use the other features of the application.\n\nThis condition can occur if you have turned off Location services for the application or are operating in Airplane mode. To reinstate the use of Location services, modify the Location setting on the Permissions flyout of the Settings charm.");
                        md.ShowAsync();
                    }
                }
            }

            // don't assume a valid location at this point GPS/Wifi disabled may lead to a null location
            if (position != null)
            {
                // register event handler to do work once the view has been reset
                TheMap.ViewChangeEnded += TheMap_ViewChangeEndedWithRefreshNeeded;

                // set pin for current location
                if (currentLocationRequested)
                {
                    TheMap.SetCurrentLocationPin(_locationMarker, position);
                }

                // pan map to desired location with a default zoom level (when complete, ViewChangeEndedWithRefreshNeeded event will fire)
                _noRefreshRequiredViewChange = true;
                TheMap.SetView(new Location(position.Latitude, position.Longitude), (Double)App.Current.Resources["DefaultZoomLevel"]);
            }
        }
コード例 #4
0
ファイル: MainPage.xaml.cs プロジェクト: winappkits/TomTomAPI
        /// <summary>
        /// Navigates map centering on given location
        /// </summary>
        /// <param name="position">Latitude/longitude point of new location (if null, current location is detected via GPS)</param>
        /// <param name="showMessage">Whether to show message informing user that location tracking is not enabled on device.</param>
        async Task GotoLocation(LatLong position, Boolean showMessage = false)
        {
            Boolean currentLocationRequested = position == null;

            try
            {
                // a null location is the cue to use geopositioning
                if (currentLocationRequested)
                {
                    try
                    {
                        Geoposition currentPosition = await _geolocator.GetGeopositionAsync();

                        position = new LatLong(currentPosition.Coordinate.Latitude, currentPosition.Coordinate.Longitude);
                    }
                    catch (Exception)
                    {
                        if (showMessage)
                        {
                            MessageDialog md =
                                new MessageDialog("This application is not able to determine your current location. This can occur if your machine is operating in Airplane mode or if the GPS sensor is otherwise not operating.");
                            md.ShowAsync();
                        }
                    }
                }

                // don't assume a valid location at this point GPS/Wifi disabled may lead to a null location
                if (position != null)
                {
                    // register event handler to do work once the view has been reset
                    TheMap.ViewChangeEnded += TheMap_ViewChangeEndedWithRefreshNeeded;

                    // set pin for current location
                    if (currentLocationRequested)
                    {
                        TheMap.SetCurrentLocationPin(_locationMarker, position);
                    }

                    // pan map to desired location with a default zoom level (when complete, ViewChangeEndedWithRefreshNeeded event will fire)
                    TheMap.SetView(new Location(position.Latitude, position.Longitude), (Double)App.Current.Resources["DefaultZoomLevel"]);
                }
            }

            // catch exception if location permission not granted
            catch (UnauthorizedAccessException)
            {
                if (showMessage)
                {
                    MessageDialog md =
                        new MessageDialog("This application has not been granted permission to capture your current location. Use the Settings charm to provide this access, then try the operation again.");
                    md.ShowAsync();
                }
            }
        }
コード例 #5
0
ファイル: MainPage.xaml.cs プロジェクト: winappkits/TomTomAPI
        /// <summary>
        /// Pans map to given location and queries for cameras now in view
        /// </summary>
        /// <param name="position">Position to which to pan the map (null indicates current location)</param>
        async Task GotoLocation(GeoCoordinate position)
        {
            Boolean currentLocationRequested = position == null;

            // turn on progress bar
            if (_apiMonitor != null)
            {
                _apiMonitor.IsExecuting = true;
            }
            DefaultViewModel.SelectedItem = null;

            // a null location is the cue to use geopositioning
            if (currentLocationRequested)
            {
                try
                {
                    _geolocator = new Geolocator();

#if DEBUG
                    // location emulator will always set current location to Redmond unless accuracy is set to High
                    _geolocator.DesiredAccuracy = PositionAccuracy.High;
#endif

                    // have to set this (or MovementThreshold) in WP8 before attaching event handlers
                    _geolocator.ReportInterval = uint.MaxValue;

                    // register callback to reset (hide) the user's location if location access is revoked while app is running
                    _geolocator.StatusChanged += (s, a) =>
                    {
                        this.Dispatcher.BeginInvoke(
                            new Windows.UI.Core.DispatchedHandler(() =>
                        {
                            if (a.Status == PositionStatus.Disabled)
                            {
                                _settingsViewModel.LocationEnabled = false;
                                _locationMarker.Visibility         = Visibility.Collapsed;
                            }
                        })
                            );
                    };

                    // get current location
                    Geoposition currentPosition = await _geolocator.GetGeopositionAsync();

                    position = currentPosition.Coordinate.ToGeoCoordinate();
                }
                catch (Exception)
                {
                    MessageBox.Show(
                        String.Format("Location services are turned off for this device, so {0} cannot plot your current position. You can, however, still search for and view camera images within the application.", AppResources.ApplicationTitle),
                        "Location services are off",
                        MessageBoxButton.OK);
                }
            }

            // don't assume a valid location at this point GPS/Wifi disabled may lead to a null location
            if (position != null)
            {
                // register event handler to do work once the view has been reset
                TheMap.ViewChanged += TheMap_ViewChanged;

                // set pin for current location
                if (currentLocationRequested)
                {
                    TheMap.SetCurrentLocationPin(_locationMarker, position);
                }

                // pan map to desired location with a default zoom level (when complete, TheMap_ViewChanged event will fire)
                TheMap.SetView(position, (Double)App.Current.Resources["DefaultZoomLevel"]);
            }

            // turn off progress bar
            if (_apiMonitor != null)
            {
                _apiMonitor.IsExecuting = false;
            }
        }