• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Geolocation.Geolocator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Windows.Devices.Geolocation.Geolocator的典型用法代码示例。如果您正苦于以下问题:C# Geolocator类的具体用法?C# Geolocator怎么用?C# Geolocator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Geolocator类属于Windows.Devices.Geolocation命名空间,在下文中一共展示了Geolocator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: GetCoordinates

        private async void GetCoordinates()
        {
            Geolocator MyGeolocator = new Geolocator();
            MyGeolocator.DesiredAccuracyInMeters = 5;
            Geoposition MyGeoPosition = null;
            try
            {
                MyGeoPosition = await MyGeolocator.GetGeopositionAsync(TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(10));
                currentGeoCoordinate = ConvertGeocoordinate(MyGeoPosition.Coordinate);

                myMap.Center = currentGeoCoordinate;
                myMap.ZoomLevel = 15;

                if (!comeinGeoCoordinate.IsUnknown)
                {
                    List<GeoCoordinate> geoCoordinates = new List<GeoCoordinate>();
                    geoCoordinates.Add(currentGeoCoordinate);
                    geoCoordinates.Add(comeinGeoCoordinate);

                    RouteQuery routeQuery = new RouteQuery();
                    routeQuery.Waypoints = geoCoordinates;
                    routeQuery.QueryCompleted += routeQuery_QueryCompleted;
                    routeQuery.QueryAsync();
                }
            }
            catch (UnauthorizedAccessException)
            {
                MessageBox.Show("Location is disabled in phone settings");
            }
            catch (Exception ex)
            {
            }
        }
开发者ID:peepo3663,项目名称:WindowsPhone8,代码行数:33,代码来源:MainPage.xaml.cs


示例2: ZoomMap

        async void ZoomMap()
        {
            var geoloc = new Geolocator();
            resultsMap.Center = (await geoloc.GetGeopositionAsync()).Coordinate.Point;
            resultsMap.ZoomLevel = 15;

        }
开发者ID:Saulmil,项目名称:FindR,代码行数:7,代码来源:Results.xaml.cs


示例3: MainPage

 public MainPage()
 {
     this.InitializeComponent();
     shopDataSourceModel = new ShopDataSourceModel(ShopDataSource.Instance);
     DataContext = shopDataSourceModel;
     _geolocator = new Geolocator();
 }
开发者ID:sugendran,项目名称:clothe-win8,代码行数:7,代码来源:MainPage.xaml.cs


示例4: obtenerposactual

        public async void obtenerposactual() // Metodo que ebtiene la posicion actual del usuario 
        {
            Geolocator migeolocalizador = new Geolocator();
            //Geoposition migeoposicion = await migeolocalizador.GetGeopositionAsync();
            Geoposition migeoposicion = null;
            try
            {
                migeoposicion = await migeolocalizador.GetGeopositionAsync();
            }
            catch (Exception ex)
            {
                if ((uint)ex.HResult == 0x80004004)
                {
                    // the application does not have the right capability or the locatiokn master switch is off
                    //feedback.Text = "location  is disabled in phone settings.";
                    MessageBox.Show("location  is disabled in phone settings.");
                }
                else
                {
                    // something else happened acquring the location
                    //feedback.Text = "Something wrong happened";
                    MessageBox.Show("Something wrong happened");
                }
            }

            Geocoordinate migeocoordenada = migeoposicion.Coordinate;
            GeoCoordinate migeoCoordenada = convertidirGeocoordinate(migeocoordenada);
            dibujaru(migeoCoordenada);
            mimapa.Center = migeoCoordenada;
            mimapa.ZoomLevel =11;
            cargarlista();

        }
开发者ID:ITESO-Ulab,项目名称:EMT_WP,代码行数:33,代码来源:1Map.xaml.cs


示例5: GetCoordinates

        private async void GetCoordinates()
        {
            // Get the phone's current location.
            Geolocator MyGeolocator = new Geolocator();
            MyGeolocator.DesiredAccuracyInMeters = 5;
            Geoposition MyGeoPosition = null;
            try
            {
                MyGeoPosition = await MyGeolocator.GetGeopositionAsync(TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(10));
                MyCoordinates.Add(new GeoCoordinate(MyGeoPosition.Coordinate.Latitude, MyGeoPosition.Coordinate.Longitude));
                Debug.WriteLine(MyGeoPosition.Coordinate.Latitude + " " + MyGeoPosition.Coordinate.Longitude);

                Mygeocodequery = new GeocodeQuery();
                Mygeocodequery.SearchTerm = "Hanoi, VN";
                Mygeocodequery.GeoCoordinate = new GeoCoordinate(MyGeoPosition.Coordinate.Latitude, MyGeoPosition.Coordinate.Longitude);

                Mygeocodequery.QueryCompleted += Mygeocodequery_QueryCompleted;
                Mygeocodequery.QueryAsync();

            }
            catch (UnauthorizedAccessException)
            {
                MessageBox.Show("Location is disabled in phone settings or capabilities are not checked.");
            }
            catch (Exception ex)
            {
                // Something else happened while acquiring the location.
                MessageBox.Show(ex.Message);
            }
        }
开发者ID:iamatsundere,项目名称:test-map,代码行数:30,代码来源:MainPage.xaml.cs


示例6: GetMyMapLocationAsync

        private async void GetMyMapLocationAsync() {
            Geolocator geolocator = new Geolocator();
            geolocator.DesiredAccuracyInMeters = 50;

            try {
                Geoposition geoposition = await geolocator.GetGeopositionAsync(
                    maximumAge: TimeSpan.FromMinutes(5),
                    timeout: TimeSpan.FromSeconds(10)
                    );

                Map.Center = new GeoCoordinate(geoposition.Coordinate.Latitude, geoposition.Coordinate.Longitude);
                Map.ZoomLevel = ZoomLevel;

                myGeoCoordinate = geoposition.Coordinate.ToGeoCoordinate();
                     
                myMapOverlay.GeoCoordinate = myGeoCoordinate;
                myMapOverlay.Content = new Pushpin() {Content = "You"};
                CalculateDistanceBetweenMeAndUser();

            } catch (Exception ex) {
                if ((uint)ex.HResult == 0x80004004) {
                    // the application does not have the right capability or the location master switch is off
                    Debug.WriteLine("Geoposition not allowed or hadrware disabled");
                }
                //else
                {
                    // something else happened acquring the location
                    Debug.WriteLine("Geoposition is not available. Failure.");

                }
            }
        }
开发者ID:Grief-Code,项目名称:kilogram,代码行数:32,代码来源:MapViewPage.xaml.cs


示例7: OnStatusChanged

        private void OnStatusChanged(Geolocator geolocator, StatusChangedEventArgs args)
        {
            switch (args.Status)
            {
                case PositionStatus.Ready:
                    break;

                case PositionStatus.Initializing:
                    break;

                case PositionStatus.NoData:
                    // TODO - trace could be useful here?
                    SendError(MvxLocationErrorCode.PositionUnavailable);
                    break;

                case PositionStatus.Disabled:
                    // TODO - trace could be useful here?
                    SendError(MvxLocationErrorCode.ServiceUnavailable);
                    break;

                case PositionStatus.NotInitialized:
                    // TODO - trace could be useful here?
                    SendError(MvxLocationErrorCode.ServiceUnavailable);
                    break;

                case PositionStatus.NotAvailable:
                    // TODO - trace could be useful here?
                    SendError(MvxLocationErrorCode.ServiceUnavailable);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
开发者ID:andyci,项目名称:MvvmCross-Plugins,代码行数:34,代码来源:MvxStoreGeoLocationWatcher.cs


示例8: OnNavigatedTo

        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            Status.Text = "Status: " + "App started";

            //compass
            var compass = Windows.Devices.Sensors.Compass.GetDefault();
            compass.ReportInterval = 10;
            //compass.ReadingChanged += compass_ReadingChanged;
            Status.Text = "Status: " + "Compass started";

            //geo
            var gloc = new Geolocator();
            gloc.GetGeopositionAsync();
            gloc.ReportInterval = 60000;
            gloc.PositionChanged += gloc_PositionChanged;
            Status.Text = "Status: " + "Geo started";

            //Accelerometer
            var aclom = Accelerometer.GetDefault();
            aclom.ReportInterval = 1;
            aclom.ReadingChanged += aclom_ReadingChanged;

            //foursquare
            await GetEstablishmentsfromWed();

            //camera
            var mediaCapture = new MediaCapture();
            await mediaCapture.InitializeAsync();
            CaptureElement.Source = mediaCapture;
            await mediaCapture.StartPreviewAsync();
            Status.Text = "Status: " + "Camera feed running";
        }
开发者ID:kfwls,项目名称:PebbrahVR,代码行数:32,代码来源:MainPage.xaml.cs


示例9: geolocator_StatusChanged

 void geolocator_StatusChanged(Geolocator sender, StatusChangedEventArgs args)
 {
     if (args.Status.Equals(PositionStatus.Ready))
     {
        
     }
 }
开发者ID:IwonaKr,项目名称:magisterka,代码行数:7,代码来源:GpsPage.xaml.cs


示例10: ShowMyLocationOnTheMap

        private async void ShowMyLocationOnTheMap()
        {
            Geolocator myGeolocator = new Geolocator();
            Geoposition myGeoposition = await myGeolocator.GetGeopositionAsync();
            Geocoordinate myGeocoordinate = myGeoposition.Coordinate;
            GeoCoordinate myGeoCoordinate = CoordinateConverter.ConvertGeocoordinate(myGeocoordinate);

            this.BettingMap.Center = myGeoCoordinate;
            this.BettingMap.ZoomLevel = 15;

            Ellipse myCircle = new Ellipse();
            myCircle.Fill = new SolidColorBrush(Colors.Blue);
            myCircle.Height = 20;
            myCircle.Width = 20;
            myCircle.Opacity = 50;

            MapOverlay myLocationOverlay = new MapOverlay();
            myLocationOverlay.Content = myCircle;
            myLocationOverlay.PositionOrigin = new Point(0.5, 0.5);
            myLocationOverlay.GeoCoordinate = myGeoCoordinate;

            MapLayer myLocationLayer = new MapLayer();
            myLocationLayer.Add(myLocationOverlay);

            BettingMap.Layers.Add(myLocationLayer);
        }
开发者ID:vlatkooo,项目名称:MyTicket,代码行数:26,代码来源:MainPage.xaml.cs


示例11: MainPage_Loaded

        /// <summary>
        /// Centers the map on current location at application launch.
        /// Subsequently only makes the map visible.
        /// </summary>
        /// <param name="sender">This page</param>
        /// <param name="e">Event arguments</param>
        private async void MainPage_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            // Make Map visible again after returning from about page.
            Map.Visibility = Visibility.Visible;

            if (geoLocator == null)
            {
                geoLocator = new Geolocator();

                try
                {
                    Geoposition pos = await geoLocator.GetGeopositionAsync();

                    if (pos != null && pos.Coordinate != null)
                    {
                        Map.SetView(new GeoCoordinate(pos.Coordinate.Latitude, pos.Coordinate.Longitude), 10);
                        GetNearbyArtists();
                    }
                }
                catch (Exception /*ex*/)
                {
                    // Couldn't get current location. Location may be disabled.
                    MessageBox.Show("Current location cannot be obtained. It is "
                                  + "recommended that location service is turned "
                                  + "on in phone settings when using Bands Around.\n"
                                  + "\nNow centering on London.");
                    Map.Center = new GeoCoordinate(51.51, -0.12);
                    Map.SetView(new GeoCoordinate(51.51, -0.12), 10);
                    GetNearbyArtists();
                }
            }
        }
开发者ID:hoangtanduy247,项目名称:wp-api-client,代码行数:38,代码来源:MainPage.xaml.cs


示例12: OnNavigatedTo

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.
        /// This parameter is typically used to configure the page.</param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            //Wait for the data to be loaded from the HSL webservice
            try
            {
                await App.VehicleViewModel.LoadVehicleDetails();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            //Get the geolocation of the phone to display in the map
            Geolocator geolocator = new Geolocator();
            Geoposition geoposition = null;
            try
            {
                geoposition = await geolocator.GetGeopositionAsync();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            hslMapControl.Center = geoposition.Coordinate.Point;
            hslMapControl.ZoomLevel = 15;
            InitiateRefreshTimer();
        }
开发者ID:nkeshri,项目名称:Jongla,代码行数:32,代码来源:MainPage.xaml.cs


示例13: GetLocation

        /// <summary>
        /// This gets the last known location or gets a new one if the last one has expired.
        /// </summary>
        /// <param name="forceUpdate">Force updates even if the location has not expired.</param>
        /// <returns>The last good location.</returns>
        public static async Task<Geoposition> GetLocation(bool forceUpdate = false)
        {
            if (GetConfirmation())
            {
                var geolocator = new Geolocator();
                geolocator.DesiredAccuracy = PositionAccuracy.High;

                try
                {
                    if (CachedLocation == null || forceUpdate || lastUpdateTime - DateTime.Now < TimeSpan.FromMinutes(5))
                    {
                        CachedLocation = await geolocator.GetGeopositionAsync(TimeSpan.FromMinutes(5), TimeSpan.FromSeconds(10));
                    }
                    return CachedLocation; 
                }
                catch (Exception ex)
                {
                    if ((uint)ex.HResult == 0x80004004)
                    {
                        MessageBox.Show("Location is disabled in phone settings.");
                    }
                    else
                    {
                        return null;
                    }
                }
            }
            return null;
        }
开发者ID:chustar,项目名称:standrighthere,代码行数:34,代码来源:GeoLocationHelper.cs


示例14: LookingFor_Loaded

        async void LookingFor_Loaded(object sender, RoutedEventArgs e)
        {
            Geolocator geolocator = new Geolocator();
            //await Task.Delay(1500);
            Geoposition geoposition = null;
            try
            {
                geoposition = AppData.GeoPosition;// await geolocator.GetGeopositionAsync();
            }

            catch (Exception ex)
            {
                // Handle errors like unauthorized access to location
                // services or no Internet access.
            }

            while (this.ViewModel.MatchingWhistles == null)
            {
                await Task.Delay(1000);
            }
            foreach (MatchingWhistles whistle in this.ViewModel.MatchingWhistles.matchingWhistles)
            {
                BasicGeoposition whistleLocation = new BasicGeoposition();
                whistleLocation.Longitude = whistle.location.coordinates[0];
                whistleLocation.Latitude = whistle.location.coordinates[1];
                AddPushpin(whistleLocation, whistle.name, whistle._id);
            }

            myMapControl.Center = geoposition.Coordinate.Point;
            myMapControl.ZoomLevel = 15;
          
        }
开发者ID:sameemir,项目名称:Whistler,代码行数:32,代码来源:LookingFor.xaml.cs


示例15: btnStart_Click

    private void btnStart_Click(object sender, RoutedEventArgs e) {

      try {
      geolocator = new Geolocator {
        DesiredAccuracy = PositionAccuracy.High, 
        MovementThreshold = 50
      };

        geolocator.StatusChanged += (sender1, args) =>

                                    Dispatcher.BeginInvoke(() =>
                                      { tbStatus.Text = args.Status.ToString(); });


        geolocator.PositionChanged += (sender1, args) => Dispatcher.BeginInvoke(() =>
          {
            tbPos.Text = string.Format("\r\n\t{0:#0.0000}\r\n\t{1:#0.0000}",
                                       args.Position.Coordinate.Latitude,
                                       args.Position.Coordinate.Longitude);
          });


        btnOneShot.IsEnabled = false;
        btnStart.IsEnabled = false;
        btnStop.IsEnabled = true;
      } catch (UnauthorizedAccessException) {
        MessageBox.Show("Bitte erlauben Sie den Zugriff auf die Location API für diese App.");
      }

     

    }
开发者ID:rolkun,项目名称:WP8Kochbuch,代码行数:32,代码来源:MainPage.xaml.cs


示例16: HandeleAccessStatus

        public async Task<Geoposition> HandeleAccessStatus(GeolocationAccessStatus accessStatus)
        {
            Geoposition geoposition = null;

            var message = "";

            switch (accessStatus)
            {
                case GeolocationAccessStatus.Allowed:
                    Geolocator geolocator = new Geolocator { DesiredAccuracyInMeters = 1000 };
                    geoposition = await geolocator.GetGeopositionAsync();
                    break;

                case GeolocationAccessStatus.Denied:
                    message = "Access to location is denied!";
                    break;

                case GeolocationAccessStatus.Unspecified:
                    message = "Unspecified error!";
                    break;
            }

            if (message != "")
            {
                this.notificator.ShowErrorToastWithDismissButton(message);
            }

            return geoposition;
        }
开发者ID:cheahengsoon,项目名称:The-Asocial-Network,代码行数:29,代码来源:GeoLocatorHelper.cs


示例17: GetLocation

        public async override Task<Location> GetLocation()
        {
            var ret = new Location();

            // create the locator
            Geolocator geolocator = new Geolocator();
            geolocator.DesiredAccuracyInMeters = 50;

            try
            {
                Geoposition geoposition = await geolocator.GetGeopositionAsync(
                    maximumAge: TimeSpan.FromMinutes(5),
                    timeout: TimeSpan.FromSeconds(10)
                    );

                // THIS IS THE ONLY DIFFERENCE
                ret.Latitude = geoposition.Coordinate.Point.Position.Latitude;
                ret.Longitude = geoposition.Coordinate.Point.Position.Longitude;
            }
            catch (Exception ex)
            {
                if ((uint)ex.HResult == 0x80004004)
                {
                    // the application does not have the right capability or the location master switch is off
                }
                else
                {
                    // something else happened acquring the location
                }
            }

            // return the location
            return ret;
        }
开发者ID:redbitdev,项目名称:ImagineCup.DevCamp.TipCalculator,代码行数:34,代码来源:MyLocationWindowsStore.cs


示例18: GetCurrentPosition

        public async Task<LocationResult> GetCurrentPosition()
        {
            try
            {
                if (!CheckConsentAskIfNotSet())
                {
                    return new LocationResult("No consent for location");
                }

                var geolocator = new Geolocator();
                geolocator.DesiredAccuracyInMeters = 50;

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

                return new LocationResult(pos);
            }
            catch (UnauthorizedAccessException)
            {
                // We were not allowed the proper right for geolocation
                return new LocationResult("Location turned off / denied");
            }
            catch (Exception)
            {
            }

            return new LocationResult("Location could not be obtained");
        }
开发者ID:christophwille,项目名称:viennarealtime,代码行数:30,代码来源:DefaultLocationService.cs


示例19: MainPage

        // Constructor
        public MainPage()
        {
            InitializeComponent();

            geolocator = new Geolocator();
            geolocator.DesiredAccuracyInMeters = 50;
        }
开发者ID:ZubaerNaseem,项目名称:maps-samples,代码行数:8,代码来源:MainPage.xaml.cs


示例20: ShowMyLocationOnTheMap

        private async void ShowMyLocationOnTheMap()
        {
            Geolocator myGeolocator = new Geolocator();
            Geoposition myGeoposition = await myGeolocator.GetGeopositionAsync();
            Geocoordinate myGeocoordinate = myGeoposition.Coordinate;
            GeoCoordinate myGeoCoordinate =
            CoordinateConverter.ConvertGeocoordinate(myGeocoordinate);


            // Make my current location the center of the Map.
            this.mapWithMyLocation.Center = myGeoCoordinate;
            this.mapWithMyLocation.ZoomLevel = 13;

            // Create a small circle to mark the current location.
            BitmapImage bmi = new BitmapImage(new Uri("/Assets/pushpinRood.png", UriKind.Relative));
            Image img = new Image();
            img.Source = bmi;

            // Create a MapOverlay to contain the circle.
            MapOverlay myLocationOverlay = new MapOverlay();
            myLocationOverlay.Content = img;
            myLocationOverlay.PositionOrigin = new Point(0.5, 0.5);
            myLocationOverlay.GeoCoordinate = myGeoCoordinate;

            // Create a MapLayer to contain the MapOverlay.
            MapLayer myLocationLayer = new MapLayer();
            myLocationLayer.Add(myLocationOverlay);

            // Add the MapLayer to the Map.
            mapWithMyLocation.Layers.Add(myLocationLayer);


 
        }
开发者ID:landerarnoys,项目名称:Shredder,代码行数:34,代码来源:MainPage.xaml.cs



注:本文中的Windows.Devices.Geolocation.Geolocator类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Geolocation.PositionChangedEventArgs类代码示例发布时间:2022-05-26
下一篇:
C# Enumeration.DeviceWatcher类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap