Provides access to the current geographic location.
        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();
            }
        }
Пример #2
0
        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.");

                }
            }
        }
Пример #3
0
 public MainPage()
 {
     this.InitializeComponent();
     shopDataSourceModel = new ShopDataSourceModel(ShopDataSource.Instance);
     DataContext = shopDataSourceModel;
     _geolocator = new Geolocator();
 }
Пример #4
0
        private async void setupGeoLocation()
        {
            // ask for permission 
            var accessStatus = await Geolocator.RequestAccessAsync();
            //check for geolocator if access is allowed or denied
            switch (accessStatus)
            {
                case GeolocationAccessStatus.Allowed:
                    {
                        await new MessageDialog(Localization.Get("setupGeo")).ShowAsync();

                        geolocator = new Geolocator();
                        geolocator.DesiredAccuracy = PositionAccuracy.High;
                        geolocator.StatusChanged += MyGeo_StatusChanged;

                        break;
                    }
                case GeolocationAccessStatus.Denied:
                    {
                        await new MessageDialog(Localization.Get("setupGeoDenied")).ShowAsync();
                        break;
                    }
                default:
                    {
                        await new MessageDialog(Localization.Get("setupGeoDefault")).ShowAsync();
                        break;
                    }
            }
        }
Пример #5
0
        private async void ShowMyLocationOnTheMap()
        {
            // Get my current location.
            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.
            Ellipse myCircle = new Ellipse();
            myCircle.Fill = new SolidColorBrush(Colors.Red);
            myCircle.Height = 20;
            myCircle.Width = 20;
            myCircle.Opacity = 50;

            // Create a MapOverlay to contain the circle.
            MapOverlay myLocationOverlay = new MapOverlay();
            myLocationOverlay.Content = myCircle;
            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);

            txTop.Text = ("My Location - Lat " + myGeoCoordinate.Latitude.ToString("0.0000") + "   Lon " + myGeoCoordinate.Longitude.ToString("0.0000"));
        }
Пример #6
0
        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";
        }
        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;
        }
Пример #8
0
        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();

        }
        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");
        }
Пример #10
0
        /// <summary>
        /// The methods provided in this section are simply used to allow
        /// NavigationHelper to respond to the page's navigation methods.
        /// <para>
        /// Page specific logic should be placed in event handlers for the  
        /// <see cref="NavigationHelper.LoadState"/>
        /// and <see cref="NavigationHelper.SaveState"/>.
        /// The navigation parameter is available in the LoadState method 
        /// in addition to page state preserved during an earlier session.
        /// </para>
        /// </summary>
        /// <param name="e">Provides data for navigation methods and event
        /// handlers that cannot cancel the navigation request.</param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            // Call the navigation helper base function.
            this.navigationHelper.OnNavigatedTo(e);

            // Get the user's current location so that it can be used as the center
            // point of the map control.
            Geolocator geolocator = new Geolocator();
            Geoposition geoposition = null;
            try
            {
                geoposition = await geolocator.GetGeopositionAsync();
            }
            catch (Exception)
            {
                // Make sure you have defined ID_CAP_LOCATION in the application manifest 
                // and that on your phone, you have turned on location by checking 
                // Settings > Location.

                // Handle errors like unauthorized access to location services
            }

            // Set the map center point.
            myMapControl.Center = geoposition.Coordinate.Point;

            // zoom level
            myMapControl.ZoomLevel = 15;

            // Various display options
            myMapControl.LandmarksVisible = false;
            myMapControl.TrafficFlowVisible = false;
            myMapControl.PedestrianFeaturesVisible = false;
        }
Пример #11
0
 async void location_StatusChanged(Geolocator sender, StatusChangedEventArgs args)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         StatusValue.Text = args.Status.ToString();
     });
 }
        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;
        }
Пример #13
0
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            geolocator = new Geolocator();
            geolocator.DesiredAccuracyInMeters = 50;
        }
Пример #14
0
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="navigationParameter">The parameter value passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
        /// </param>
        /// <param name="pageState">A dictionary of state preserved by this page during an earlier
        /// session.  This will be null the first time a page is visited.</param>
        protected override async void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
        {
            // Allow saved page state to override the initial item to display
            if (pageState != null && pageState.ContainsKey("SelectedItem"))
            {
                navigationParameter = pageState["SelectedItem"];
            }

            Geolocator locator = new Geolocator();
            Geoposition geoPos = await locator.GetGeopositionAsync();
            Geocoordinate geoCoord = geoPos.Coordinate;

            String YWSID = "Bi9Fsbfon92vmD4DkkO4Fg";
            String url;

            if (navigationParameter != "")
            {
                url = "http://api.yelp.com/business_review_search?term=food&location=" + navigationParameter + "&ywsid=" + YWSID;
            }
            else
            {
                url = "http://api.yelp.com/business_review_search?term=food&lat=" + geoCoord.Latitude + "&long=" + geoCoord.Longitude + "&ywsid=" + YWSID;
            }
            var httpClient = new HttpClient();
            String content = await httpClient.GetStringAsync(url);
            response = JsonObject.Parse(content);

            this.Frame.Navigate(typeof(MainPage),response);
        }
Пример #15
0
        /// <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();
                }
            }
        }
Пример #16
0
 void geolocator_StatusChanged(Geolocator sender, StatusChangedEventArgs args)
 {
     if (args.Status.Equals(PositionStatus.Ready))
     {
        
     }
 }
Пример #17
0
        public async void  getLocationAddress()
        {
     


             Geolocator geolocator = new Geolocator();
            Geoposition currentPosition = await geolocator.GetGeopositionAsync();
            string address = "pretoria";
            MapLocationFinderResult result = await MapLocationFinder.FindLocationsAsync(
              address, currentPosition.Coordinate.Point, 5);

            if (result.Status == MapLocationFinderStatus.Success)
            {
                List<string> locations = new List<string>();
                foreach (MapLocation mapLocation in result.Locations)
                {
                    // create a display string of the map location
                    string display = mapLocation.Address.StreetNumber + " " +
                       mapLocation.Address.Street + Environment.NewLine +
                      mapLocation.Address.Town + ", " +
                      mapLocation.Address.RegionCode + "  " +
                      mapLocation.Address.PostCode + Environment.NewLine +
                      mapLocation.Address.CountryCode;
                    // Add the display string to the location list.
                    locations.Add(display);
                   address = display;
                   lstView.Items.Add("location          " + display);
                }
            }

       
        }
Пример #18
0
        /// <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();
        }
Пример #19
0
        async void ZoomMap()
        {
            var geoloc = new Geolocator();
            resultsMap.Center = (await geoloc.GetGeopositionAsync()).Coordinate.Point;
            resultsMap.ZoomLevel = 15;

        }
Пример #20
0
        /// <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;
        }
Пример #21
0
        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)
            {
            }
        }
Пример #22
0
        private async void findMe()
        {
            Windows.Devices.Geolocation.Geolocator  geolocator  = new Windows.Devices.Geolocation.Geolocator();
            Windows.Devices.Geolocation.Geoposition geoposition = await geolocator.GetGeopositionAsync();

            myMap.SetView(new Bing.Maps.Location()
            {
                Latitude = geoposition.Coordinate.Latitude, Longitude = geoposition.Coordinate.Longitude
            }, 13);
            Bing.Maps.MapLayer.SetPosition(pin, new Bing.Maps.Location()
            {
                Latitude = geoposition.Coordinate.Latitude, Longitude = geoposition.Coordinate.Longitude
            });
            myMap.SetView(new Bing.Maps.Location()
            {
                Latitude = geoposition.Coordinate.Latitude, Longitude = geoposition.Coordinate.Longitude
            });
            myMap.Children.Clear();
            myMap.ShapeLayers.Clear();
            Bing.Maps.MapLayer.SetPosition(pin, new Bing.Maps.Location()
            {
                Latitude = geoposition.Coordinate.Latitude, Longitude = geoposition.Coordinate.Longitude
            });
            myMap.Children.Add(pin);
            sourseLocation = new Bing.Maps.Location()
            {
                Latitude = geoposition.Coordinate.Latitude, Longitude = geoposition.Coordinate.Longitude
            };
        }
Пример #23
0
        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);
        }
Пример #24
0
        public async Task <Windows.Devices.Geolocation.Geocoordinate> GetSinglePositionAsync()
        {
            Windows.Devices.Geolocation.Geolocator  geolocator  = new Windows.Devices.Geolocation.Geolocator();
            Windows.Devices.Geolocation.Geoposition geoposition = await geolocator.GetGeopositionAsync();

            return(geoposition.Coordinate);
        }
Пример #25
0
        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);


 
        }
Пример #26
0
        private async void PegaLocal ()
        {

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

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

                dLatitude = geoposition.Coordinate.Latitude;
                dLongetude = geoposition.Coordinate.Longitude;
            }
            catch (Exception ex)
            {
                if ((uint)ex.HResult == 0x80004004)
                {
                    // the application does not have the right capability or the location master switch is off
                    dLatitude = 0;
                    dLongetude = 0;
                }
                //else
                {
                    // something else happened acquring the location
                }
            }
        }
        private async void OnLocatorStatusChanged(Windows.Devices.Geolocation.Geolocator sender, StatusChangedEventArgs e)
        {
            GeolocationError error;

            switch (e.Status)
            {
            case PositionStatus.Disabled:
                error = GeolocationError.Unauthorized;
                break;

            case PositionStatus.NoData:
                error = GeolocationError.PositionUnavailable;
                break;

            default:
                return;
            }

            if (isListening)
            {
                await StopListeningAsync();

                OnPositionError(new PositionErrorEventArgs(error));
            }

            locator = null;
        }
Пример #28
0
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     location = new Geolocator();
     location.PositionChanged += location_PositionChanged;
     location.StatusChanged += location_StatusChanged;
     //GetLocationDataOnce();
 }
Пример #29
0
    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.");
      }

     

    }
Пример #30
0
        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;
          
        }
Пример #31
0
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            _geoLocator = null;
            _isTracking = false;
        }
Пример #32
0
        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);
            }
        }
Пример #33
0
        public SubCategoriesPage()
        {
            this.InitializeComponent();

            // Setup the navigation helper
            this.navigationHelper = new NavigationHelper(this);
            this.navigationHelper.LoadState += navigationHelper_LoadState;
            this.navigationHelper.SaveState += navigationHelper_SaveState;

            // Setup the logical page navigation components that allow
            // the page to only show one pane at a time.
            this.navigationHelper.GoBackCommand = new ZebritasWin8.Common.RelayCommand(() => this.GoBack(), () => this.CanGoBack());
            this.lsvSubCategories.SelectionChanged += itemListView_SelectionChanged;

            // Start listening for Window size changes 
            // to change from showing two panes to showing a single pane
            Window.Current.SizeChanged += Window_SizeChanged;
            this.InvalidateVisualState();
            watcher = new Geolocator();
            watcher.MovementThreshold = 200;
            latitude = 150;
            longitude = 150;
            comingBack = false;
            this.Loaded += SubCategoriesPage_Loaded;
            //prgPlaces.Visibility = System.Windows.Visibility.Visible;
        }
Пример #34
0
        async static void InitialPosition(Sensor sensor)
        {
            try
            {
                var geopos = await sensor.GetGeopositionAsync();

                position = geopos.Coordinate;
            }
            catch { }
        }
 private void EnsureStopped()
 {
     if (_geolocator != null)
     {
         // TODO - is this enough to stop it?
         _geolocator.PositionChanged -= OnPositionChanged;
         _geolocator.StatusChanged   -= OnStatusChanged;
         _geolocator = null;
     }
 }
        private Windows.Devices.Geolocation.Geolocator GetGeolocator()
        {
            var loc = locator;

            if (loc == null)
            {
                locator = new Windows.Devices.Geolocation.Geolocator();
                locator.StatusChanged += OnLocatorStatusChanged;
                loc = locator;
            }

            return(loc);
        }
Пример #37
0
        static int startUpdateLocation(int L)
        {
            Geolocator watcher = new Windows.Devices.Geolocation.Geolocator();

            //System.Device.Location.GeoCoordinateWatcher watcher = new GeoCoordinateWatcher();
            //watcher.Start();
            watcher.DesiredAccuracy         = PositionAccuracy.Default;
            watcher.DesiredAccuracyInMeters = 10;
            watcher.MovementThreshold       = 10;
            watcher.ReportInterval          = 10;

            Lua.Lua_pushlightuserdata(L, watcher);

            return(1);
        }
Пример #38
0
        void OnReadingChanged(Sensor sender, PositionChangedEventArgs args)
        {
            var handler    = changed;
            var coordinate = args.Position != null ? args.Position.Coordinate : null;

            if (coordinate != null)
            {
                if (handler != null)
                {
                    var value = ConvertToPosition(coordinate);
                    var e     = new GpsEventArgs(value);
                    handler.Invoke(this, e);
                }

                position = coordinate;
            }
        }
        protected override void PlatformSpecificStart(MvxGeoLocationOptions options)
        {
            if (_geolocator != null)
            {
                throw new MvxException("You cannot start the MvxLocation service more than once");
            }

            // see https://github.com/slodge/MvvmCross/issues/90
            _geolocator = new Geolocator
            {
                // DesiredAccuracy = TODO options.EnableHighAccuracy
                // MovementThreshold = TODO
                // ReportInterval = TODO
            };

            _geolocator.StatusChanged   += OnStatusChanged;
            _geolocator.PositionChanged += OnPositionChanged;
        }
Пример #40
0
        static int stopUpdateLocation(int L)
        {
            if (!LuaCommon.CheckAndShowArgsError(L, LConst.UserData))
            {
                return(0);
            }

            Windows.Devices.Geolocation.Geolocator watcher = (Windows.Devices.Geolocation.Geolocator)Lua.Lua_touserdata(L, -1);
            if (watcher != null && _GeoChangedRegistry != null)
            {
                _GeoChangedRegistry.RemoveAll(k => k.Key.Equals(watcher));
                watcher.PositionChanged -= GeoChangedCallback4Lua;

                //watcher.Stop();
            }

            return(0);
        }
Пример #41
0
        /// <summary>
        /// Initialize Geolocation and get position
        /// </summary>
        private async void InitializeGeolocation()
        {
            try
            {
                var locator = new Windows.Devices.Geolocation.Geolocator();
                locator.DesiredAccuracy         = PositionAccuracy.High;
                locator.DesiredAccuracyInMeters = 10;
                var task = locator.GetGeopositionAsync();
                while (task.Status == Windows.Foundation.AsyncStatus.Started)
                {
                    await Task.Delay(300);
                }
                Geoposition position = null;
                if (task.Status == Windows.Foundation.AsyncStatus.Completed)
                {
                    position = task.GetResults();
                }
                else
                {
                    StatusLbl.Text = task.Status.ToString();
                    if (task.Status == Windows.Foundation.AsyncStatus.Error)
                    {
                        StatusLbl.Text = StatusLbl.Text + ": " + task.ErrorCode.Message;
                    }
                    return;
                }

                StatusLbl.Text = LocRM.GetString("Status") + ": " + locator.LocationStatus.ToString();
                if (position != null)
                {
                    StatusLbl.Text   += " [" + position.Coordinate.PositionSource.ToString() + "]";
                    AccuracyLbl.Text  = LocRM.GetString("GeolocationAccuracy") + ": " + position.Coordinate.Accuracy.ToString();
                    LatitudeLbl.Text  = LocRM.GetString("GeolocationLatitude") + ": " + position.Coordinate.Point.Position.Latitude.ToString();
                    LongitudeLbl.Text = LocRM.GetString("GeolocationLongitude") + ": " + position.Coordinate.Point.Position.Longitude.ToString();
                }
            }
            catch (Exception e)
            {
                Log.LogError(e.ToString());
                AccuracyLbl.Text = LocRM.GetString("Error");
            }
        }
Пример #42
0
        /// <summary>
        /// Locators the status changed.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="args">The <see cref="StatusChangedEventArgs"/> instance containing the event data.</param>
        private void LocatorStatusChanged(Windows.Devices.Geolocation.Geolocator sender, StatusChangedEventArgs args)
        {
            switch (args.Status)
            {
            case PositionStatus.Disabled:
                PositionError.TryInvoke(sender, new PositionErrorEventArgs(GeolocationError.Unauthorized));
                break;

            case PositionStatus.Initializing:
                break;

            case PositionStatus.NoData:
                PositionError.TryInvoke(sender, new PositionErrorEventArgs(GeolocationError.PositionUnavailable));
                break;

            case PositionStatus.NotInitialized:
                IsListening = false;
                break;

            case PositionStatus.Ready:
                IsListening = true;
                break;
            }
        }
Пример #43
0
 void geo_PositionChanged(Windows.Devices.Geolocation.Geolocator sender, Windows.Devices.Geolocation.PositionChangedEventArgs args)
 {
     // TODO
 }
 private void OnLocatorPositionChanged(Windows.Devices.Geolocation.Geolocator sender, PositionChangedEventArgs e)
 {
     OnPositionChanged(new PositionEventArgs(GetPosition(e.Position)));
 }
Пример #45
0
 /// <summary>
 /// Return an instance of CLLocationManager to set properties
 /// </summary>
 public static CLLocationManager GetLocationManager(this Geolocator instance)
 => instance.LocationManager;
Пример #46
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Geolocator" /> class.
 /// </summary>
 public Geolocator()
 {
     _locator = new Windows.Devices.Geolocation.Geolocator();
 }
Пример #47
0
 /// <summary>
 /// Locators the position changed.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="args">The <see cref="PositionChangedEventArgs"/> instance containing the event data.</param>
 private void LocatorPositionChanged(Windows.Devices.Geolocation.Geolocator sender, PositionChangedEventArgs args)
 {
     PositionChanged.TryInvoke(sender, new PositionEventArgs(args.Position.Coordinate.GetPosition()));
 }