示例#1
0
 private async void LoadLocation()
 {
     Windows.Devices.Geolocation.Geoposition l = null;
     try
     {
         var loc = new Windows.Devices.Geolocation.Geolocator();
         l = position = await loc.GetGeopositionAsync();
     }
     catch { return; }
     foreach (var coll in new GraphicsOverlayCollection[] {
         sceneView.GraphicsOverlays, mapView.GraphicsOverlays
     })
     {
         GraphicsOverlay overlay = new GraphicsOverlay();
         coll.Add(overlay);
         Graphic g = new Graphic()
         {
             Symbol = new SimpleMarkerSymbol()
             {
                 Color   = System.Drawing.Color.FromArgb(255, 0, 122, 194),
                 Size    = 20,
                 Outline = new SimpleLineSymbol()
                 {
                     Width = 2,
                     Color = System.Drawing.Color.White
                 }
             },
         };
         g.Geometry = new MapPoint(l.Coordinate.Point.Position.Longitude, l.Coordinate.Point.Position.Latitude, SpatialReferences.Wgs84);
         overlay.Graphics.Add(g);
         break;
     }
 }
		private async void LoadLocation()
		{
			Windows.Devices.Geolocation.Geoposition l = null;
			try
			{
				var loc = new Windows.Devices.Geolocation.Geolocator();
				l = position = await loc.GetGeopositionAsync();

			}
			catch { return; }
			foreach (var coll in new GraphicsOverlayCollection[] { 
				sceneView.GraphicsOverlays , mapView.GraphicsOverlays
			})
			{
				GraphicsOverlay overlay = new GraphicsOverlay();
				coll.Add(overlay);
				Graphic g = new Graphic()
				{
					Symbol = new SimpleMarkerSymbol()
					{
						Color = Color.FromArgb(255, 0, 122, 194),
						Size = 20,
						Outline = new SimpleLineSymbol()
						{
							Width = 2,
							Color = Colors.White
						}
					},

				};
				g.Geometry = new MapPoint(l.Coordinate.Point.Position.Longitude, l.Coordinate.Point.Position.Latitude, SpatialReferences.Wgs84);
				overlay.Graphics.Add(g);
				break;
			}
		}
示例#3
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            var p = await Windows.Storage.ApplicationData.Current.LocalFolder.GetBasicPropertiesAsync();

            Windows.Devices.Geolocation.Geolocator l = new Windows.Devices.Geolocation.Geolocator();
            var loc = await l.GetGeopositionAsync();
        }
 protected override async void OnNavigatedTo(NavigationEventArgs e)
 {
     base.OnNavigatedTo(e);
     if (e.Parameter is string[])
     {
         var stop = await Data.GetBusStop(((string[])e.Parameter)[1], CancellationTokenSource.Token);
         var route = await Data.GetRoute(((string[])e.Parameter)[0], CancellationTokenSource.Token);
         string destination = ((string[])e.Parameter)[2];
         DescriptionBlock.Text = route.Value.Name + " to " + destination + " at " + stop.Value.Name;
         Windows.Devices.Geolocation.Geolocator locator = new Windows.Devices.Geolocation.Geolocator();
         TitleBox.Text = destination;
         string city = null;
         try
         {
             var finder = await MapLocationFinder.FindLocationsAtAsync(new Windows.Devices.Geolocation.Geopoint(stop.Value.Position));
             if (finder.Locations.Count > 0)
             {
                 city = finder.Locations[0].Address.Town;
                 CityContextBox.IsEnabled = true;
                 CityContextBox.Content = "In " + city;
             }
             else
             {
                 CityContextBox.Content = "(Could not get city)";
             }
         }
         catch (Exception)
         {
             CityContextBox.Content = "(Could not get city)";
         }
         location = new ContextLocation() { Latitude = stop.Value.Position.Latitude, Longitude = stop.Value.Position.Longitude, City = city };
         favorite = new FavoriteArrival() { Contexts = new LocationContext[0], Route = route.Value.ID, Stop = stop.Value.ID, Destination = destination };
     }
 }
示例#5
0
        public static async Task<Windows.Devices.Geolocation.Geoposition> GetMachineLocation()
        {
            Windows.Devices.Geolocation.Geoposition rtn = null;

            try
            {
                Windows.Devices.Geolocation.GeolocationAccessStatus accessStatus = await Windows.Devices.Geolocation.Geolocator.RequestAccessAsync();
                switch(accessStatus)
                {
                    case Windows.Devices.Geolocation.GeolocationAccessStatus.Allowed:
                        Windows.Devices.Geolocation.Geolocator geolocator = new Windows.Devices.Geolocation.Geolocator();
                        rtn = await geolocator.GetGeopositionAsync();
                        break;
                    case Windows.Devices.Geolocation.GeolocationAccessStatus.Denied:
                        rtn = null;
                        break;
                    case Windows.Devices.Geolocation.GeolocationAccessStatus.Unspecified:
                        rtn = null;
                        break;
                }
            }
            finally
            {

            }

            return rtn;
        }
示例#6
0
 private void Locator_OnStatusChanged(
     Windows.Devices.Geolocation.Geolocator sender,
     Windows.Devices.Geolocation.StatusChangedEventArgs args)
 {
     this.LocationStatus = args.Status.ToLocalPositionStatus();
     this.StatusChanged?.Invoke(this, new StatusChangedEventArgs(this.LocationStatus));
 }
        public static async Task <(double latitude, double longitude)> GetCoordinates()
        {
#if NET461
            return(await Task.Run(async() =>
            {
                using (var watcher = new System.Device.Location.GeoCoordinateWatcher())
                {
                    watcher.TryStart(true, TimeSpan.FromSeconds(1));
                    while (watcher.Position.Location.IsUnknown)
                    {
                        await Task.Delay(TimeSpan.FromMilliseconds(100));
                    }

                    var location = watcher.Position.Location;
                    return (location.Latitude, location.Longitude);
                }
            }));
#elif WINDOWS_UWP
            var locator  = new Windows.Devices.Geolocation.Geolocator();
            var position = await locator.GetGeopositionAsync();

            var latitude  = position.Coordinate.Point.Position.Latitude;
            var longitude = position.Coordinate.Point.Position.Longitude;
            return(latitude, longitude);
#else
            throw new PlatformNotSupportedException();
#endif
        }
示例#8
0
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            ClearRubyText();

#if DEBUG
            InputText.Text = "日本語の漢字・カナ交じりの文字列です。山河と山川、須弥山登山計画";
#endif

#if DEBUG
            // 以下、説明用のコード (このアプリの動作には関係がない)

            // JapanesePhoneticAnalyzer は Windows 8.1 から使える
            // ただし、半角英数字を全角に変換してくれちゃうのが玉に瑕
            // http://www.atmarkit.co.jp/ait/articles/1511/25/news028.html
            IReadOnlyList <Windows.Globalization.JapanesePhoneme> list
                = Windows.Globalization.JapanesePhoneticAnalyzer.GetWords("日本語の文字列abc");
            foreach (var phoneme in list)
            {
                // 分割した文字列(形態素)
                string displayText = phoneme.DisplayText;

                // 分割した文字列の読み仮名
                string yomiText = phoneme.YomiText;

                // この形態素は句の先頭か?
                bool isPhraseStart = phoneme.IsPhraseStart;

                // 形態素ごとに何か処理をする
            }


            // 使える API
            var geolocator  = new Windows.Devices.Geolocation.Geolocator();
            var geoposition = await geolocator.GetGeopositionAsync();

            // 使えない (DualApiPartition属性が付いていない)
            //bool isContract5Present
            //  = Windows.Foundation.Metadata.ApiInformation
            //      .IsApiContractPresent("Windows.Foundation.UniversalApiContract", 5);

            // 使えない (API が package identity を必要とするため)
            try
            {
                var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
            }
            catch (InvalidOperationException ex)
            {
                var exMsg = ex.Message;
                // exMsg: "プロセスにパッケージ ID がありません。 (HRESULT からの例外:0x80073D54)"
            }


            // 使える
            var gamepad = Windows.Gaming.Input.Gamepad.Gamepads.FirstOrDefault();

            // 使えない (UwpDesktop が 15063 に未対応なため)
            //var flightStick = Windows.Gaming.Input.FlightStick.FlightSticks.FirstOrDefault();
#endif
        }
示例#9
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            var p = await Windows.Storage.ApplicationData.Current.LocalFolder.GetBasicPropertiesAsync();

            Windows.Devices.Geolocation.Geolocator l = new Windows.Devices.Geolocation.Geolocator();
            var loc = await l.GetGeopositionAsync();

        }
示例#10
0
 private void Geolocator_PositionChanged(Windows.Devices.Geolocation.Geolocator sender, Windows.Devices.Geolocation.PositionChangedEventArgs args)
 {
     if (sender.LocationStatus == Windows.Devices.Geolocation.PositionStatus.Ready)
     {
         MSIoTKiTHoLJP.IoTHoLConfig.Latitude  = args.Position.Coordinate.Point.Position.Latitude;
         MSIoTKiTHoLJP.IoTHoLConfig.Longitude = args.Position.Coordinate.Point.Position.Longitude;
     }
 }
示例#11
0
        public async void cnAsync()
        {
            var locator  = new Windows.Devices.Geolocation.Geolocator();
            var location = await locator.GetGeopositionAsync();

            var position = location.Coordinate.Point.Position;
            var uriMe    = new Uri(@"ms-settings:privacy-location");
        }
        UnsafeUpdateGeoposition()
        {
            var geolocator  = new Windows.Devices.Geolocation.Geolocator();
            var geoposition = await geolocator.GetGeopositionAsync(maximumAge : TimeSpan.FromMinutes(1),
                                                                   timeout : TimeSpan.FromSeconds(10));

            return(geoposition.Coordinate.Point.Position);
        }
示例#13
0
        private async void GetCurrentPosition()
        {
            var locator  = new Windows.Devices.Geolocation.Geolocator();
            var location = await locator.GetGeopositionAsync();

            var position = location.Coordinate.Point.Position;
            var latlong  = string.Format("lat:{0}, long:{1}", position.Latitude, position.Longitude);
            var result   = MessageBox.Show(latlong);
        }
        /// <summary>
        /// Check if location permission is already granted.
        /// </summary>
        /// <returns>Return true if location permission is granted, else false.</returns>
        private bool IsPermissionGrantedImpl()
        {
            // Re-use the geolocator if found
            var winGeolocator = WindowsGeolocator;

            if (winGeolocator == null)
            {
                winGeolocator = new Windows.Devices.Geolocation.Geolocator();
            }
            return(winGeolocator.LocationStatus != Windows.Devices.Geolocation.PositionStatus.Disabled);
        }
示例#15
0
        public async Task Find()
        {
            var geolocator = new Windows.Devices.Geolocation.Geolocator();
            var position   = await geolocator.GetGeopositionAsync();

            CurrentLocation = new Location
            {
                Latitude  = position.Coordinate.Point.Position.Latitude,
                Longitude = position.Coordinate.Point.Position.Longitude,
            };
        }
示例#16
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var locator  = new Windows.Devices.Geolocation.Geolocator();
            var location = await locator.GetGeopositionAsync();

            var position = location.Coordinate.Point.Position;
            var latlong  = string.Format("lat:{0}, long:{1}", position.Latitude, position.Longitude);

            Console.WriteLine(latlong);
        }
示例#17
0
        async void geolocatorButton_Click(object sender, RoutedEventArgs e)
        {
            // 使える API
            var locator  = new Windows.Devices.Geolocation.Geolocator();
            var position = await locator.GetGeopositionAsync();

            var point = position.Coordinate.Point.Position;

            geolocatorText.Text = string.Format("Latitude(北緯+):{0}, Longitude(東経+):{1}",
                                                point.Latitude, point.Longitude);
        }
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            var geolocator = new Windows.Devices.Geolocation.Geolocator()
            {
                DesiredAccuracyInMeters = 5
            };
            var pos = await geolocator.GetGeopositionAsync();

            LongBlock.Text = $"{pos.Coordinate.Point.Position.Longitude:#.00}";
            LatBlock.Text  = $"{pos.Coordinate.Point.Position.Latitude:#.00}";
            await TheMap.TrySetViewAsync(pos.Coordinate.Point, 15.0);
        }
示例#19
0
        UnsafeUpdateGeoposition()
        {
            var geolocator = new Windows.Devices.Geolocation.Geolocator
            {
                DesiredAccuracyInMeters = 0
            };

            var pos = await geolocator.GetGeopositionAsync(maximumAge : TimeSpan.FromMinutes(5),
                                                           timeout : TimeSpan.FromSeconds(10));

            return(pos.Coordinate.Point.Position);
        }
        public async Task<GeoCoords> GetLocationAsync()
        {
            var geolocator = new Windows.Devices.Geolocation.Geolocator();
            var geoposition = await geolocator.GetGeopositionAsync();

            var coords = new GeoCoords
            {
                Latitude = geoposition.Coordinate.Latitude,
                Longitude = geoposition.Coordinate.Longitude
            };

            return coords;
        }
示例#21
0
        public async Task <GeoCoords> GetGeoCoordinatesAsync()
        {
            var geolocator  = new Windows.Devices.Geolocation.Geolocator();
            var geoposition = await geolocator.GetGeopositionAsync();

            var coords = new GeoCoords
            {
                Latitude  = geoposition.Coordinate.Latitude,
                Longitude = geoposition.Coordinate.Longitude
            };

            return(coords);
        }
示例#22
0
        private async void Geolocator_PositionChanged(Windows.Devices.Geolocation.Geolocator sender, Windows.Devices.Geolocation.PositionChangedEventArgs args)
        {
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                MapGraphics.Graphics.Clear();

                var stopPoint = MapHelper.CreateRouteStop(
                    args.Position.Coordinate.Point.Position.Latitude,
                    args.Position.Coordinate.Point.Position.Longitude,
                    System.Drawing.Color.Red
                    );
                MapGraphics.Graphics.Add(stopPoint);
            });
        }
示例#23
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            timer.Tick += (s, arg) =>
            {
                gotoBtn.Visibility = Visibility.Visible;
                timer.Stop();
            };
            timer.Start();
            Windows.Devices.Geolocation.Geolocator location = new Windows.Devices.Geolocation.Geolocator();
            try
            {
                var position = await location.GetGeopositionAsync();

                if (position != null)
                {
                    double[] data = { position.Coordinate.Point.Position.Latitude, position.Coordinate.Point.Position.Longitude };
                    Frame.Navigate(typeof(WebViewPage), data);
                }
            }
            catch (Exception)
            {
                var dialog = new Windows.UI.Popups.MessageDialog("无法定位,请打开定位开关以获取您的出发地点")
                {
                    Title = "提示"
                };
                dialog.Commands.Add(new Windows.UI.Popups.UICommand("转到设置")
                {
                    Id = 0
                });
                dialog.Commands.Add(new Windows.UI.Popups.UICommand("忽略")
                {
                    Id = 1
                });
                dialog.DefaultCommandIndex = 0;
                var res = await dialog.ShowAsync();

                if ((int)res.Id == 1)
                {
                    Frame.Navigate(typeof(WebViewPage));
                }
                if ((int)res.Id == 0)
                {
                    await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-location"));

                    Application.Current.Exit();
                }
            }
        }
        /// <summary>
        /// Start listen to location update / gather device location.
        /// </summary>
        private async void StartLocationUpdate()
        {
            // Don't start another Windows geolocator if there is one already running
            if (WindowsGeolocator == null)
            {
                var isRequestLocationSuccessful = false;
                var isLastKnownLocationUseable  = false;

                try
                {
                    // Acquire a reference to the system Windows geolocator
                    WindowsGeolocator = new Windows.Devices.Geolocation.Geolocator()
                    {
                        DesiredAccuracyInMeters = (int)DefaultTargetAccuracy,
                        ReportInterval          = 0
                    };

                    // Try get the last known location or current device location
                    if (!UpdateLocation(await WindowsGeolocator.GetGeopositionAsync()))
                    {
                        // Then request the location update
                        WindowsGeolocator.PositionChanged += WindowsGeolocator_PositionChanged;
                    }
                    else
                    {
                        // No need to get new location since we already have the location
                        isLastKnownLocationUseable = true;
                    }

                    isRequestLocationSuccessful = true;
                }
                catch
                {
                    // Ignore all error including lack of permission or provider is not enabled
                }

                // Stop location service if initialized failed or we already have the location
                if (!isRequestLocationSuccessful)
                {
                    StopLocationUpdate(GeolocationStatus.SetupError);
                }
                else if (isLastKnownLocationUseable)
                {
                    StopLocationUpdate(GeolocationStatus.Successful);
                }
            }
        }
        private async void Start(bool start)
        {
            // validate settings
            System.Diagnostics.Contracts.Contract.Assert(this.BeginStory != null, "BeginStory is required");
            System.Diagnostics.Contracts.Contract.Assert(this.DecideStory != null, "DecideStory is required");
            System.Diagnostics.Contracts.Contract.Assert(this.RevealStory != null, "RevealStory is required");
            System.Diagnostics.Contracts.Contract.Assert(this.ClearStory != null, "ClearStory is required");
            System.Diagnostics.Contracts.Contract.EndContractBlock();

            // setup in app purchase (simulate when debugging)
            m_HideAdsFeature = await new InAppPurchaseHelper(HIDEADSFAETURENAME, Strings.SimulatePurchasing).Setup();
            this.HideAds     = m_HideAdsFeature.IsPurchased;

            // setup data/questions
            AddQuestions();

            // clear any vars
            this.Score = 0;
            Selected   = string.Empty;
            HighScore  = HighScore;

            // start
            if (start)
            {
                NextQuestion();
            }

            // update location
            if (Strings.IncludeAdvertising)
            {
                try
                {
                    var _Location = new Windows.Devices.Geolocation.Geolocator();
                    var _Position = await _Location.GetGeopositionAsync();

                    this.Latitude  = _Position.Coordinate.Latitude;
                    this.Longitude = _Position.Coordinate.Longitude;
                }
                catch
                {
                    // this breakpoint may be reached if the user BLOCKS location services
                    System.Diagnostics.Debugger.Break();
                }
            }
        }
示例#26
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            if (e.Parameter is string[])
            {
                var stop = await Data.GetBusStop(((string[])e.Parameter)[1], CancellationTokenSource.Token);

                var route = await Data.GetRoute(((string[])e.Parameter)[0], CancellationTokenSource.Token);

                string destination = ((string[])e.Parameter)[2];
                DescriptionBlock.Text = route.Value.Name + " to " + destination + " at " + stop.Value.Name;
                Windows.Devices.Geolocation.Geolocator locator = new Windows.Devices.Geolocation.Geolocator();
                TitleBox.Text = destination;
                string city = null;
                try
                {
                    var finder = await MapLocationFinder.FindLocationsAtAsync(new Windows.Devices.Geolocation.Geopoint(stop.Value.Position));

                    if (finder.Locations.Count > 0)
                    {
                        city = finder.Locations[0].Address.Town;
                        CityContextBox.IsEnabled = true;
                        CityContextBox.Content   = "In " + city;
                    }
                    else
                    {
                        CityContextBox.Content = "(Could not get city)";
                    }
                }
                catch (Exception)
                {
                    CityContextBox.Content = "(Could not get city)";
                }
                location = new ContextLocation()
                {
                    Latitude = stop.Value.Position.Latitude, Longitude = stop.Value.Position.Longitude, City = city
                };
                favorite = new FavoriteArrival()
                {
                    Contexts = new LocationContext[0], Route = route.Value.ID, Stop = stop.Value.ID, Destination = destination
                };
            }
        }
示例#27
0
        private async void button1_Click(object sender, EventArgs e)
        {
            Windows.Storage.StorageFolder localCacheFolder = Windows.Storage.ApplicationData.Current.LocalCacheFolder;

            StorageFile sf = await localCacheFolder.CreateFileAsync("dataFile.txt", CreationCollisionOption.ReplaceExisting);

            label.Text = sf.Path;

            var locator  = new Windows.Devices.Geolocation.Geolocator();
            var location = await locator.GetGeopositionAsync();

            var position = location.Coordinate.Point.Position;
            var latlong  = string.Format("lat:{0}, long:{1}", position.Latitude, position.Longitude);

            label2.Text = latlong;

            webView1.Navigate("https://www.bing.com");
            webView1.Update();
        }
示例#28
0
 void geolocator_PositionChanged(Windows.Devices.Geolocation.Geolocator sender, Windows.Devices.Geolocation.PositionChangedEventArgs args)
 {
     if (this.IsListening)
     {
         var      position = args.Position;
         Position p        = new Position()
         {
             Accuracy         = position.Coordinate.Accuracy,
             Altitude         = position.Coordinate.Altitude,
             AltitudeAccuracy = position.Coordinate.AltitudeAccuracy,
             Heading          = position.Coordinate.Heading,
             Latitude         = position.Coordinate.Latitude,
             Longitude        = position.Coordinate.Longitude,
             Speed            = position.Coordinate.Speed,
             Timestamp        = position.Coordinate.Timestamp.DateTime
         };
         this.PositionChanged(sender, new PositionEventArgs(p));
     }
 }
示例#29
0
        private async void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            if (Guid.Empty == MSIoTKiTHoLJP.IoTHoLConfig.DeviceID)
            {
                FixDeviceId();
                if (deviceId == "minwinpc")
                {
                    Debug.Write("Please set deviceID or unique machine name");
                    throw new ArgumentOutOfRangeException("Please set deviceID or unique machine name");
                }
            }
            else
            {
                deviceId = MSIoTKiTHoLJP.IoTHoLConfig.DeviceID.ToString();
            }
            tbDeviceId.Text = deviceId.ToString();
            fezHat          = await GIS.FEZHAT.CreateAsync();

            fezHat.D2.TurnOff();
            fezHat.D3.TurnOff();
            try
            {
                var result = await TryConnect();

                if (result)
                {
                    await InitializeUpload();
                }
                geolocator = new Windows.Devices.Geolocation.Geolocator();
                geolocator.PositionChanged += Geolocator_PositionChanged;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            lastSensorReading     = new List <SensorReadingBuffer>();
            measureTimer          = new DispatcherTimer();
            measureTimer.Interval = TimeSpan.FromMilliseconds(measureIntervalMSec);
            measureTimer.Tick    += MeasureTimer_Tick;
            measureTimer.Start();
        }
        /// <summary>
        /// Stop listen to location update / gatherer device location.
        /// </summary>
        private void StopLocationUpdate(GeolocationStatus status)
        {
            if (WindowsGeolocator != null)
            {
                WindowsGeolocator.PositionChanged -= WindowsGeolocator_PositionChanged;
                WindowsGeolocator = null;
            }

            // Make sure we only update the result if it is not completed yet
            if (LocationTaskCompletionSource != null &&
                !LocationTaskCompletionSource.Task.IsCompleted)
            {
                // Craft the location with all information we have whatever the location is acceptable or not
                var location = IsLastKnownLocationFresh() ?
                               LastKnownLocation.ToNewGeolocation(status) :
                               new Geolocation(status);

                // return the location
                LocationTaskCompletionSource.SetResult(location);
            }
        }
示例#31
0
        private async void Geolocator_PositionChanged(Windows.Devices.Geolocation.Geolocator sender, Windows.Devices.Geolocation.PositionChangedEventArgs args)
        {
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                MapGraphics.Graphics.Where(g =>
                {
                    if (g.Attributes.ContainsKey("id"))
                    {
                        return((string)g.Attributes["id"] != "currentLocation");
                    }
                    return(true);
                });

                var currentLocation = MapHelper.CreateRouteStop(
                    args.Position.Coordinate.Point.Position.Latitude,
                    args.Position.Coordinate.Point.Position.Longitude,
                    System.Drawing.Color.Red
                    );
                currentLocation.Attributes.Add("id", "currentLocation");
                MapGraphics.Graphics.Add(currentLocation);
            });
        }
示例#32
0
        public async Task <NetPortableServices.Geoposition> GetGeopositionAsync(TimeSpan maximumAge, TimeSpan timeout)
        {
            try
            {
                var geolocator = new Windows.Devices.Geolocation.Geolocator();
                geolocator.DesiredAccuracyInMeters = 50;

                var geoposition = await geolocator.GetGeopositionAsync(maximumAge, timeout);

                if (geoposition == null || geoposition.Coordinate == null)
                {
                    return(null);
                }
                return(new NetPortableServices.Geoposition {
                    Latitude = geoposition.Coordinate.Latitude, Longitude = geoposition.Coordinate.Longitude
                });
            }
            catch (Exception)
            {
                return(null);
            }
        }
示例#33
0
        void geolocator_StatusChanged(Windows.Devices.Geolocation.Geolocator sender, Windows.Devices.Geolocation.StatusChangedEventArgs args)
        {
            if (this.IsListening)
            {
                switch (args.Status)
                {
                case Windows.Devices.Geolocation.PositionStatus.Disabled:
                case Windows.Devices.Geolocation.PositionStatus.Initializing:
                    break;

                case Windows.Devices.Geolocation.PositionStatus.NoData:
                case Windows.Devices.Geolocation.PositionStatus.NotAvailable:
                    this.PositionError(sender, new PositionErrorEventArgs(GeolocationError.PositionUnavailable));
                    break;

                case Windows.Devices.Geolocation.PositionStatus.NotInitialized:
                    this.PositionError(sender, new PositionErrorEventArgs(GeolocationError.Unauthorized));
                    break;

                case Windows.Devices.Geolocation.PositionStatus.Ready:
                    break;
                }
            }
        }
 private async Task<Position> GetCurrentPosition()
 {
     try
     {
         var geolocator = new Windows.Devices.Geolocation.Geolocator();
         var location = await geolocator.GetGeopositionAsync();
         var position = new Position
         {
             Latitude = location.Coordinate.Point.Position.Latitude,
             Longitude = location.Coordinate.Point.Position.Longitude
         };
         return position;
     }
     catch (Exception ex)
     {
         //Set position manually in case of failure
         //Approximate location of TechEd NA 2014
         Position location = new Position {
             Latitude = 29.751826,
             Longitude = -95.360190
         };
         return location;
     }
 }
        public async Task Start()
        {
            AddFeeds();

            // at first we will only reload from cache (so it's fast)
            RefreshFromCache();

            // setup in app purchase (simulate when debugging)
            if (Strings.AdInclude)
            {
                m_HideAdsFeature = await new InAppPurchaseHelper(HideAdsFeatureName, Strings.AdSimulatePurchasing).Setup();
                this.HideAds     = m_HideAdsFeature.IsPurchased;
            }

            // share score
            Windows.ApplicationModel.DataTransfer.DataTransferManager
            .GetForCurrentView().DataRequested += (s, e) =>
            {
                var _String = string.Format(Strings.ShareHtml,
                                            SelectedArticle.Title, SelectedArticle.Author,
                                            SelectedArticle.Date, SelectedArticle.Url,
                                            this.Feeds.First(x => x.Articles.Contains(SelectedArticle)).Feed.MoreUrl);
                var _Html = Windows.ApplicationModel.DataTransfer.HtmlFormatHelper.CreateHtmlFormat(_String);
                e.Request.Data.Properties.Title       = Strings.ShareTitle;
                e.Request.Data.Properties.Description = string.Empty;
                e.Request.Data.SetUri(new Uri(SelectedArticle.Url));
                e.Request.Data.SetHtmlFormat(_Html);
                SelectedArticle = null;
            };
            this.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName.Equals("SelectedArticle"))
                {
                    if (SelectedArticle is AdvertArticle)
                    {
                        SelectedArticle = null;
                    }
                    if (SelectedArticle is WeatherArticle)
                    {
                        SelectedArticle = null;
                    }
                    if (SelectedArticle != null)
                    {
                        Windows.ApplicationModel.DataTransfer.DataTransferManager.ShowShareUI();
                    }
                }
            };

            // update location
            if (Strings.AdInclude)
            {
                try
                {
                    var _Geo      = new Windows.Devices.Geolocation.Geolocator();
                    var _Position = await _Geo.GetGeopositionAsync(TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(5));

                    this.Latitude  = _Position.Coordinate.Latitude;
                    this.Longitude = _Position.Coordinate.Longitude;
                }
                catch { Debug.WriteLine("Error reading location; user may have BLOCKED"); }
            }
        }
        public static bool IsLocationServicesDISABLE()
        {
            var geolocator = new Windows.Devices.Geolocation.Geolocator();

            return geolocator.LocationStatus == Windows.Devices.Geolocation.PositionStatus.Disabled;
        }
示例#37
0
        private async void ToolBtnsClicked(object sender, SelectionChangedEventArgs e)
        {
            var list = sender as GridView;

            switch (list.SelectedIndex)
            {
            case 0:
                //考试查询
                (Window.Current.Content as Frame).Navigate(typeof(WebViewPage), "http://112.124.54.19/Score/index.html?identity=" + Class.UserManager.UserData.identity);
                list.SelectedIndex = -1;
                break;

            case 1:
                //OneNote
                list.SelectedIndex = -1;
                await Windows.System.Launcher.LaunchUriAsync(new Uri("onenote:"));

                break;

            case 2:
                //考试倒计时
                var dialog1 = new Controls.DialogBox()
                {
                    Title               = "提示",
                    PrimaryButtonText   = "取消",
                    SecondaryButtonText = "确定",
                };
                dialog1.mainTextBlock.Text = "尚未完成";
                await dialog1.ShowAsync();

                list.SelectedIndex = -1;
                break;

            case 3:
                //滴滴打车
                LoadProgress.IsActive = true;
                list.SelectedIndex    = -1;
                if (!Windows.Storage.ApplicationData.Current.LocalSettings.Values.ContainsKey("firstdidi_" + Edi.UWP.Helpers.Utils.GetAppVersion()))
                {
                    await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-windows-store://pdp/?productid=9p1l6rlcfr5r"));

                    Windows.Storage.ApplicationData.Current.LocalSettings.Values["firstdidi_" + Edi.UWP.Helpers.Utils.GetAppVersion()] = true;
                }
                Windows.Devices.Geolocation.Geolocator location = new Windows.Devices.Geolocation.Geolocator();
                try
                {
                    var position = await location.GetGeopositionAsync();

                    if (position != null)
                    {
                        string url = string.Format(@"http://common.diditaxi.com.cn/general/webEntry?from=sdkwebapp&hack=allbiz&openid=TWpjek1UVTVPVFF4TVRnMk5nPT0%3D&channel=71650&datatype=webapp&sign=116b6136e919ecc743704bf8c41352621473005289&openid=TWpjek1UVTVPVFF4TVRnMk5nPT0%3D&phone={0}&fromlat={1}&biz=1&fromlng={2}#", Class.UserManager.UserData.mobileNumber, position.Coordinate.Point.Position.Latitude, position.Coordinate.Point.Position.Longitude);
                        (Window.Current.Content as Frame).Navigate(typeof(WebViewPage), url);
                    }
                }
                catch (Exception)
                {
                    var dialog = new Controls.DialogBox()
                    {
                        Title               = "提示",
                        PrimaryButtonText   = "取消",
                        SecondaryButtonText = "转到设置",
                    };
                    LoadProgress.IsActive     = false;
                    dialog.mainTextBlock.Text = "无法定位,请打开定位开关!";
                    if (await dialog.ShowAsync() == ContentDialogResult.Secondary)
                    {
                        await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-location"));
                    }
                }
                LoadProgress.IsActive = false;
                break;

            case 4:
                //Office Lens
                list.SelectedIndex = -1;
                await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-windows-store://pdp/?PFN=Microsoft.OfficeLens_8wekyb3d8bbwe"));

                break;

            default:
                break;
            }
        }