2

我的 mainpage.xaml.cs 代码

我在appstudio.windows.com 上为windows phone 8.1 创建了这个web 视图应用程序,我尝试在visual studio 2015 中编辑代码。我希望地理定位应该在webview 中集成的网页上工作。手机显示位置图标但无法检索地理坐标。我已在清单中打开位置功能。谁能告诉我哪里出错了。

任何帮助都会拯救我。提前致谢。

    using System;
    using Windows.ApplicationModel.DataTransfer;
    using Windows.Phone.UI.Input;
    using Windows.UI.ViewManagement;
    using Windows.UI.Xaml;
    using Windows.UI.Xaml.Controls;
    using Windows.UI.Xaml.Navigation;
    using CFORCABSOfficial.ViewModels;
    using CFORCABSOfficial.Wat;
    using Windows.Devices.Geolocation;

   namespace CFORCABSOfficial.Views
   {

    public sealed partial class MainPage : Page
    {
        private MainViewModel _mainViewModel = null;
        private DataTransferManager _transferManager = null;
        private Uri _currentUri = null;

        public MainPage()
        {
            this.InitializeComponent();
            this.NavigationCacheMode = NavigationCacheMode.Required;

            _mainViewModel = _mainViewModel ?? new MainViewModel();
            DataContext = this;
            ApplicationView.GetForCurrentView().
            SetDesiredBoundsMode(ApplicationViewBoundsMode.UseVisible);


            var splash = App.CurrentSplashScreen;
            if (splash != null)
            {
                // Optional: Add a progress ring to your splash screen to show users that content is loading
                PositionRing();
            }

            WatConfig.LoadConfigAsync(this.MainWebView, this.BottomCommandBar);
            this.MainWebView.NavigationCompleted += OnFirstLoadNavigationCompleted;
            HardwareButtons.BackPressed += OnBackPressed;
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            _transferManager = _transferManager ?? DataTransferManager.GetForCurrentView();
            _transferManager.DataRequested += OnDataRequested;
        }

        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            base.OnNavigatedFrom(e);
            _transferManager.DataRequested -= OnDataRequested;
        }

        private void OnDataRequested(DataTransferManager sender, DataRequestedEventArgs args)
        {
            _mainViewModel.GetDataShare(args.Request, _currentUri);
        }

        /// <summary>
        /// Handles back button press.  If app is at the root page of app, don't go back and the
        /// system will suspend the app.
        /// </summary>
        /// <param name="sender">The source of the BackPressed event.</param>
        /// <param name="e">Details for the BackPressed event.</param>
        private void OnBackPressed(object sender, BackPressedEventArgs e)
        {
            var RootFrame = Window.Current.Content as Frame;
            if (RootFrame == null)
            {
                return;
            }
            if (RootFrame.CanGoBack)
            {
                RootFrame.GoBack();
                e.Handled = true;
            }

            if (this.MainWebView.CanGoBack)
            {
                string url = MainWebView.Source.ToString();

                String url2 = "http://windows.xyz.com/member-index.php";
                String url3 = "http://windows.xyz.com/index2.php";
                if ( url != url2) 
                { 
                MainWebView.Navigate(new Uri("http://windows.xyz.com/member-index.php"));
                    e.Handled = true;
               }
if (url == url3)
                { App.Current.Exit(); }
if (url == url2)
                { App.Current.Exit(); }
            }
        }

        #region "ExtendSplashScreen"
        void PositionRing()
        {
            splashProgressRing.SetValue(Canvas.LeftProperty, Window.Current.Bounds.Width / 2.2);
            splashProgressRing.SetValue(Canvas.TopProperty, Window.Current.Bounds.Height / 5);
        }
        #endregion

        public MainViewModel MainViewModel
        {
            get { return _mainViewModel; }
        }

        private void OnFirstLoadNavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args)
        {
            this.MainWebView.Visibility = Visibility.Visible;
            this.loadingCanvas.Visibility = Visibility.Collapsed;
            this.BottomAppBar.Visibility = Visibility.Visible;

            this.MainWebView.NavigationCompleted -= OnFirstLoadNavigationCompleted;
            this._currentUri = args.Uri;

            this.MainWebView.NavigationStarting += OnNavigationStarting;
            this.MainWebView.NavigationCompleted += OnNavigationCompleted;

            _transferManager.DataRequested += OnDataRequested;

        }

        private async void OnNavigationStarting(WebView sender, WebViewNavigationStartingEventArgs args)
        {
            var statusBar = Windows.UI.ViewManagement.StatusBar.GetForCurrentView();
            await statusBar.ProgressIndicator.ShowAsync();
            Geolocator myGeolocator = new Geolocator();
            {
                Geoposition myGeoposition = await myGeolocator.GetGeopositionAsync();
                Geocoordinate myGeocoordinate = myGeoposition.Coordinate;
            }
  }


        private async void OnNavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args)
        {
            this._currentUri = args.Uri;
            var statusBar = Windows.UI.ViewManagement.StatusBar.GetForCurrentView();
            await statusBar.ProgressIndicator.HideAsync();
            // Carry out the operation.

        }
        }
        }
4

0 回答 0