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(); }
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 }
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; } }
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; }
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 }
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); }
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"); }
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); }
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, }; }
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); }
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); }
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); }
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); }
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; }
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); }
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(); } } }
public async Task <Position> GetPositionAsync(bool includeHeading) { var position = await geolocator.GetGeopositionAsync(); return(new Position() { Accuracy = position.Coordinate.Accuracy, Altitude = position.Coordinate.Altitude, AltitudeAccuracy = position.Coordinate.AltitudeAccuracy, Heading = (includeHeading) ? position.Coordinate.Heading : null, Latitude = position.Coordinate.Latitude, Longitude = position.Coordinate.Longitude, Speed = position.Coordinate.Speed, Timestamp = position.Coordinate.Timestamp.DateTime }); }
/// <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(); } } }
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(); }
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); } }
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; } }
private async void GetNearSchools() { progressBar.Visibility = Visibility.Visible; if (HttpPostUntil.isInternetAvailable) { try { label1: Windows.Devices.Geolocation.Geolocator location = new Windows.Devices.Geolocation.Geolocator(); try { var position = await location.GetGeopositionAsync(); if (position != null) { var postdata = HttpPostUntil.GetBasicPostData(); postdata.Add(new KeyValuePair <string, string>("lng", position.Coordinate.Point.Position.Longitude.ToString())); postdata.Add(new KeyValuePair <string, string>("lat", position.Coordinate.Point.Position.Latitude.ToString())); var json = await HttpPostUntil.HttpPost(Data.Urls.user.Register.getRecommendSchoolList, new Windows.Web.Http.HttpFormUrlEncodedContent(postdata), false); json = JsonObject.Parse(json).GetNamedObject("data").GetNamedArray("schoolBOs").ToString(); var schools = Data.Json.DataContractJsonDeSerialize <List <School> >(json); if (schools != null) { foreach (var item in schools) { nearschools.Add(item); } } else { Tools.ShowMsgAtFrame("附近没有学校"); } } } 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) { goto label1; } if ((int)res.Id == 0) { await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-location")); } } } catch (Exception) { Tools.ShowMsgAtFrame("网络异常"); } } else { Tools.ShowMsgAtFrame("网络异常"); } progressBar.Visibility = Visibility.Collapsed; }
public async Task Start() { // timer m_Timer.Tick += (s, e) => { var _Delta = new DateTime(2013, 5, 17).Subtract(DateTime.Now); this.SubTitle = _Delta.ToString("d' Days 'h' Hours 'm' Minutes 's' Seconds'"); }; m_Timer.Start(); AddFeeds(false); // at first we will only reload from cache (so it's fast) RefreshFromCache(); // setup in app purchase (simulate when debugging) if (Strings.IncludeAdvertising) { m_HideAdsFeature = await new InAppPurchaseHelper(HideAdsFeatureName, Strings.SimulatePurchasing).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 SummaryArticle) { SelectedArticle = null; } if (SelectedArticle is AdvertArticle) { SelectedArticle = null; } if (SelectedArticle is WeatherArticle) { SelectedArticle = null; } if (SelectedArticle != null) { Windows.ApplicationModel.DataTransfer.DataTransferManager.ShowShareUI(); } } }; // 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 Debug.WriteLine("Error reading location; user may have BLOCKED"); System.Diagnostics.Debugger.Break(); } } }
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"); } } }
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; } }