Ejemplo n.º 1
0
        public async void InitCurrentLocationInfo()
        {
            Task <GeoCoordinate> x = ShowMyCurrentLocationOnTheMap();

            geoQ.GeoCoordinate = await x;

            geoQ.QueryAsync();

            //txtboxStart.Text = showString;
        }
        public Task <IEnumerable <string> > GetAddress(double lat, double lng)
        {
            var taskCompletion = new TaskCompletionSource <IEnumerable <string> >();
            EventHandler <QueryCompletedEventArgs <IList <MapLocation> > > handler = null;
            var reverseGeocode = new ReverseGeocodeQuery();

            reverseGeocode.GeoCoordinate = new GeoCoordinate(lat, lng);

            handler = (s, e) =>
            {
                reverseGeocode.QueryCompleted -= handler;
                if (e.Cancelled)
                {
                    taskCompletion.SetCanceled();
                }
                else if (e.Error != null)
                {
                    taskCompletion.SetException(e.Error);
                }
                else
                {
                    var addresses = e.Result.Select(m => AddressToString(m.Information.Address));
                    taskCompletion.SetResult(addresses);
                }
            };

            reverseGeocode.QueryCompleted += handler;
            reverseGeocode.QueryAsync();

            return(taskCompletion.Task);
        }
Ejemplo n.º 3
0
        void Start_ReverceGeoCoding(MapOverlay Marker)
        {
            if (geoRev.IsBusy != true && (Marker != null))
            {
                if (Marker == DestinationMarker)
                {
                    DestinationRevGeoNow         = true;
                    DestinationTitle.Text        = "";
                    GeoProgress2.IsEnabled       = true;
                    GeoProgress2.IsIndeterminate = true;
                }
                else
                {
                    DestinationRevGeoNow         = false;
                    OriginTitle.Text             = "";
                    GeoProgress1.IsEnabled       = true;
                    GeoProgress1.IsIndeterminate = true;
                }

                // Set the geo coordinate for the query
                geoRev.GeoCoordinate = Marker.GeoCoordinate;
                geoRev.QueryAsync();
                Debug.WriteLine("RevGeocodeAsync started for location: ");
            }
        }
        private async void GetCurrentCoordinate()
        {
            LocationProgressBar.Visibility = System.Windows.Visibility.Visible;
            textBoxPostalCode.Text = "";
            Geolocator geolocator = new Geolocator();
            geolocator.DesiredAccuracy = PositionAccuracy.High;

            try
            {
                Geoposition currentPosition = await geolocator.GetGeopositionAsync(TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(10));
                _accuracy = currentPosition.Coordinate.Accuracy;

                MyCoordinate = new GeoCoordinate(currentPosition.Coordinate.Latitude, currentPosition.Coordinate.Longitude);

                if (MyReverseGeocodeQuery == null || !MyReverseGeocodeQuery.IsBusy)
                {
                    MyReverseGeocodeQuery = new ReverseGeocodeQuery();
                    MyReverseGeocodeQuery.GeoCoordinate = new GeoCoordinate(MyCoordinate.Latitude, MyCoordinate.Longitude);
                    MyReverseGeocodeQuery.QueryCompleted += ReverseGeocodeQuery_QueryCompleted;
                    MyReverseGeocodeQuery.QueryAsync();
                }
            }
            catch (Exception)
            {
                invalidMessage.Text = "Unable to find Valid Postal Code";
            }
        }
Ejemplo n.º 5
0
        private async void centromapa()
        {
            geolocator.DesiredAccuracyInMeters = 50;
            try
            {
                SetProgressindicator(true);
                SystemTray.ProgressIndicator.Text = "Obteniendo datos del GPS";
                Geoposition geoposition = await geolocator.GetGeopositionAsync
                                              (maximumAge : TimeSpan.FromMinutes(5),
                                              timeout : TimeSpan.FromSeconds(10));

                SystemTray.ProgressIndicator.Text = "Localizacion obtenida";
                mapacentral.Center.Latitude       = geoposition.Coordinate.Latitude;
                mapacentral.Center.Longitude      = geoposition.Coordinate.Longitude;
                centrox = geoposition.Coordinate.Latitude;
                centroy = geoposition.Coordinate.Longitude;
                ReverseGeocodeQuery query = new ReverseGeocodeQuery();
                query.GeoCoordinate   = new GeoCoordinate(geoposition.Coordinate.Latitude, geoposition.Coordinate.Longitude);
                query.QueryCompleted += (s, e) =>
                {
                    if (e.Error == null && e.Result.Count > 0)
                    {
                        listacercanos.Header = e.Result.ToString();
                    }
                };
                query.QueryAsync();
                track();
                pinchosmapa();
            }
            catch (UnauthorizedAccessException)
            {          // the app does not have the right capability or the location master switch is off
                listacercanos.Header = "location  is disabled in phone settings.";
            }
        }
Ejemplo n.º 6
0
        //METODOS DE LOCALIZACION Y MAPA
        //busca la ubicacion, situa al usuario y al mapa, e inicia el seguimiento
        private async void iniciamapa()
        {
            geolocator.DesiredAccuracyInMeters = DesiredAccuracyInMeters;
            geolocator.DesiredAccuracy         = PositionAccuracy.High;
            try
            {
                prog.IsVisible = true;
                prog.Text      = "Obteniendo localización";
                IAsyncOperation <Geoposition> locationTask = null;
                try
                {
                    locationTask = geolocator.GetGeopositionAsync(TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(15));
                    Geoposition   position        = await locationTask;
                    Geocoordinate myGeocoordinate = position.Coordinate;
                    GeoCoordinate myGeoCoordinate = ConvertGeocoordinate(myGeocoordinate);
                    centro    = myGeoCoordinate;
                    prog.Text = "Localización obtenida";
                    this.mapacentral.Center = myGeoCoordinate;
                    usuariocordx            = position.Coordinate.Latitude;
                    usuariocordy            = position.Coordinate.Longitude;
                    setPosition(position.Coordinate.Latitude, position.Coordinate.Longitude);

                    ReverseGeocodeQuery query = new ReverseGeocodeQuery();
                    query.GeoCoordinate   = new GeoCoordinate(position.Coordinate.Latitude, position.Coordinate.Longitude);
                    query.QueryCompleted += ReverseGeocodeQuery_QueryCompleted;
                    query.QueryAsync();

                    localespincho(position.Coordinate.Latitude, position.Coordinate.Longitude);
                    Uri url = new Uri("http://produccion.rl2012alc.com/api/index.php/setPosition ");
                    objetoslistas.getByCoord paquete = new objetoslistas.getByCoord();
                    paquete.latitude  = position.Coordinate.Latitude;
                    paquete.longitude = position.Coordinate.Longitude;
                    string respuesta = await metodosJson.jsonPOST(url, paquete);

                    if (listapinchos.Count > 0)
                    {
                        checklocal();
                    }
                }
                finally
                {
                    if (locationTask != null)
                    {
                        if (locationTask.Status == AsyncStatus.Started)
                        {
                            locationTask.Cancel();
                        }
                        locationTask.Close();
                    }
                }
            }
            catch (Exception)
            {
                // the app does not have the right capability or the location master switch is off
                MessageBoxResult result = MessageBox.Show("Location  is disabled in phone settings", "ERROR", MessageBoxButton.OK);
            }
        }
Ejemplo n.º 7
0
        private void Marker_Click(object sender, EventArgs e)
        {
            Polygon       p             = (Polygon)sender;
            GeoCoordinate geoCoordinate = (GeoCoordinate)p.Tag;

            MyReverseGeocodeQuery = new ReverseGeocodeQuery();
            MyReverseGeocodeQuery.GeoCoordinate   = new GeoCoordinate(geoCoordinate.Latitude, geoCoordinate.Longitude);
            MyReverseGeocodeQuery.QueryCompleted += ReverseGeocodeQuery_QueryCompleted;
            MyReverseGeocodeQuery.QueryAsync();
        }
Ejemplo n.º 8
0
        private void map_Hold(object sender, System.Windows.Input.GestureEventArgs e)
        {
            g = map.ConvertViewportPointToGeoCoordinate(e.GetPosition(map));

            ReverseGeocodeQuery MyGeocodeQuery = new ReverseGeocodeQuery();

            MyGeocodeQuery.GeoCoordinate = g;

            MyGeocodeQuery.QueryCompleted += MyGeocodeQuery_QueryCompleted;
            MyGeocodeQuery.QueryAsync();
        }
Ejemplo n.º 9
0
        public static async void GetCurrentDeviceGeoLocation()
        {
            Geocoordinate GeoCorResult = await GetCurrentGeoPosition();
            CurrentCity = new City();
            CurrentCity.Latitude = GeoCorResult.Latitude;
            CurrentCity.Longitude = GeoCorResult.Longitude;

            ReverseGeocodeQuery RGeoQ = new ReverseGeocodeQuery();
            RGeoQ.GeoCoordinate = new GeoCoordinate(GeoCorResult.Latitude, GeoCorResult.Longitude);
            RGeoQ.QueryCompleted += reverseGeocode_QueryCompleted;
            RGeoQ.QueryAsync();
        }
Ejemplo n.º 10
0
        void textt_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (geoQ.IsBusy == true)
            {
                geoQ.CancelAsync();
            }
            // Set the geo coordinate for the query
            geoQ.GeoCoordinate = map1.Center;

            geoQ.QueryAsync();
            Debug.WriteLine("RevGeocodeAsync started for location: ");
        }
Ejemplo n.º 11
0
        async void connectionManager_MessageReceived(string message)
        {
            Debug.WriteLine("Message received:" + message);
            //string[] messageArray = message.Split(':');
            //switch (messageArray[0])

            switch (message)
            {
                case "f":
                    // send emergency alert
                    Dispatcher.BeginInvoke(delegate()
                    {
                        // find GPS location - continuous
                        // find address - Reverse Geocoding
                        ReverseGeocodeQuery query = new ReverseGeocodeQuery()
                        {
                            GeoCoordinate = new GeoCoordinate(Lat, Long)
                        };
                        query.QueryCompleted += query_QueryCompleted;
                        query.QueryAsync();

                    });
                break;
                case "s":
                    //reduce life
                    life--;
                    
                    Dispatcher.BeginInvoke(delegate()
                    {
                        // make ui changes
                        Life.Text = life.ToString();

                        if (life <= 0)
                            Life.Text = "Lost";
                        
                    });
                break;
                default :
                //if (float.Parse(message) > 0.0 && float.Parse(message) < 99.0)
                //{
                //    Temp.Text = message;
                //}
                Dispatcher.BeginInvoke(delegate()
                {
                    // make ui changes
                    Temp.Text = message;

                });
                
                break;
            }
        }
Ejemplo n.º 12
0
        private async void GetCurrentCoordinate()
        {
            Geolocator locator = new Geolocator();

            locator.DesiredAccuracy = PositionAccuracy.High;
            Geoposition position = await locator.GetGeopositionAsync();

            GeoCoordinate       coordinate = new GeoCoordinate(position.Coordinate.Latitude, position.Coordinate.Longitude);
            ReverseGeocodeQuery query      = new ReverseGeocodeQuery();

            query.GeoCoordinate = coordinate;
            query.QueryAsync();
            query.QueryCompleted += Query_QueryCompleted;
        }
Ejemplo n.º 13
0
 void geolocator_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
 {
     Dispatcher.BeginInvoke(() =>
     {
         mapacentral.Center = new GeoCoordinate(args.Position.Coordinate.Latitude, args.Position.Coordinate.Longitude);
         centrox            = args.Position.Coordinate.Latitude;
         centroy            = args.Position.Coordinate.Longitude;
         pinchosmapa();
         ReverseGeocodeQuery query = new ReverseGeocodeQuery();
         query.GeoCoordinate       = new GeoCoordinate(args.Position.Coordinate.Latitude, args.Position.Coordinate.Longitude);
         query.QueryCompleted     += ReverseGeocodeQuery_QueryCompleted;
         query.QueryAsync();
     });
 }
Ejemplo n.º 14
0
        static Task <IEnumerable <string> > GetAddressesForPositionAsync(Position position)
        {
            var source = new TaskCompletionSource <IEnumerable <string> >();

            var query = new ReverseGeocodeQuery
            {
                GeoCoordinate = new GeoCoordinate(position.Latitude, position.Longitude)
            };

            query.QueryCompleted +=
                (sender, args) => source.SetResult(args.Result.Select(r => AddressToString(r.Information.Address)).ToArray());
            query.QueryAsync();

            return(source.Task);
        }
Ejemplo n.º 15
0
        private void ShowLocationInfo()
        {
            var position = CurrentPosition;

            var query = new ReverseGeocodeQuery()
            {
                GeoCoordinate = new GeoCoordinate(position.Latitude, position.Longitude)
            };

            query.QueryCompleted += OnQueryCompleted;

            _systemTrayService.Show("Retrieving current location info...");

            query.QueryAsync();
        }
Ejemplo n.º 16
0
        private void Start_ReverseGeocodeQuery()
        {
            reverseGeocodeQuery = new ReverseGeocodeQuery()
            {
                GeoCoordinate = new GeoCoordinate(latitude, longitude)
            };

            spinnerSP.SetValue(Grid.RowProperty, 2);
            spinnerSP.SetValue(Grid.RowSpanProperty, 1);

            myMap.Center     = reverseGeocodeQuery.GeoCoordinate;
            myMap.Visibility = Visibility.Visible;

            reverseGeocodeQuery.QueryCompleted += reverseGeocodeQuery_QueryCompleted;
            reverseGeocodeQuery.QueryAsync();
        }
Ejemplo n.º 17
0
 private void GetNearbyArtists()
 {
     try
     {
         if (reverseGeocode == null || !reverseGeocode.IsBusy)
         {
             reverseGeocode = new ReverseGeocodeQuery();
             reverseGeocode.GeoCoordinate   = new GeoCoordinate(Map.Center.Latitude, Map.Center.Longitude);
             reverseGeocode.QueryCompleted += reverseGeocode_QueryCompleted;
             reverseGeocode.QueryAsync();
         }
     }
     catch (Exception /*ex*/)
     {
         MessageBox.Show("Something went wrong");
     }
 }
    public static Task <Location> ReverseGeocode(double lat, double lon)
    {
        TaskCompletionSource <Location> completionSource = new TaskCompletionSource <Location>();
        var geocodeQuery = new ReverseGeocodeQuery();

        geocodeQuery.GeoCoordinate = new GeoCoordinate(lat, lon);
        EventHandler <QueryCompletedEventArgs <IList <MapLocation> > > query = null;

        query = (sender, args) =>
        {
            geocodeQuery.QueryCompleted -= query;
            MapLocation mapLocation = args.Result.FirstOrDefault();
            var         location    = Location.FromMapLocation(mapLocation);
            completionSource.SetResult(location);
        };
        geocodeQuery.QueryCompleted += query;
        geocodeQuery.QueryAsync();
    }
        /// <summary>
        /// Retrieve addresses for position.
        /// </summary>
        /// <param name="position">Desired position (latitude and longitude)</param>
        /// <returns>Addresses of the desired position</returns>
        public Task <IEnumerable <Address> > GetAddressesForPositionAsync(Position position)
        {
            if (position == null)
            {
                return(null);
            }

            var source = new TaskCompletionSource <IEnumerable <Address> >();

            var query = new ReverseGeocodeQuery
            {
                GeoCoordinate = new GeoCoordinate(position.Latitude, position.Longitude)
            };

            query.QueryCompleted += (sender, args) => source.SetResult(args.Result.ToAddresses());
            query.QueryAsync();

            return(source.Task);
        }
Ejemplo n.º 20
0
        //metodo que se lanza cada vez que la posicion del gps cambia, almacena la posicion del usuario
        //y lanza una actualizacion del centro del mapa y de la direccion postal
        private void Watcher_PositionChanged(object sender, GeoPositionChangedEventArgs <GeoCoordinate> e)
        {
            usuariocordx = e.Position.Location.Latitude;
            usuariocordy = e.Position.Location.Longitude;
            centro       = new GeoCoordinate(e.Position.Location.Latitude, e.Position.Location.Longitude);
            mapacentral.SetView(centro, mapacentral.ZoomLevel);
            mapacentral.Layers.Clear();
            localespincho(e.Position.Location.Latitude, e.Position.Location.Longitude);
            MapLayer mapLayer = new MapLayer();

            DrawMapMarker(centro, Colors.Purple, mapLayer);
            mapacentral.Layers.Add(mapLayer);


            ReverseGeocodeQuery query = new ReverseGeocodeQuery();

            query.GeoCoordinate   = new GeoCoordinate(e.Position.Location.Latitude, e.Position.Location.Longitude);
            query.QueryCompleted += ReverseGeocodeQuery_QueryCompleted;
            query.QueryAsync();
        }
Ejemplo n.º 21
0
        public Task <string> GetAddress(double latitude, double longitude)
        {
            string Address = "";
            var    tcs     = new TaskCompletionSource <string>();

            System.EventHandler <Microsoft.Phone.Maps.Services.QueryCompletedEventArgs <System.Collections.Generic.IList <Microsoft.Phone.Maps.Services.MapLocation> > > handler = null;
            var reverseGeocode = new ReverseGeocodeQuery();

            handler = (sender, args) =>
            {
                foreach (var address in args.Result.Select(adrInfo => adrInfo.Information.Address))
                {
                    ;
                    if (address.Street != "" && address.HouseNumber != "")
                    {
                        Address += address.Street + " ";
                        Address += address.HouseNumber + ",\n";
                    }
                    else
                    {
                        if (address.Street != "" && address.HouseNumber == "")
                        {
                            Address += address.Street + " ";
                        }
                    }
                    Address += address.City + ", ";
                    Address += address.Country;
                }
                if (Address == "")
                {
                    Address = latitude + ",\n" + longitude;
                }
                reverseGeocode.QueryCompleted -= handler;
                tcs.SetResult(Address);
            };

            reverseGeocode.GeoCoordinate   = new GeoCoordinate(latitude, longitude);
            reverseGeocode.QueryCompleted += handler;
            reverseGeocode.QueryAsync();
            return(tcs.Task);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Get a city name from given coordinates.
        /// </summary>
        /// <param name="latitude"></param>
        /// <param name="longitude"></param>
        /// <returns></returns>
        public Task <string> GetCityFromLocation(double latitude, double longitude)
        {
            TaskCompletionSource <string> taskComplete = new TaskCompletionSource <string>();

            ReverseGeocodeQuery query = new ReverseGeocodeQuery()
            {
                GeoCoordinate = new GeoCoordinate(latitude, longitude)
            };

            query.QueryCompleted += (s, e) =>
            {
                if (e.Error == null)
                {
                    taskComplete.SetResult(e.Result.First().Information.Address.City);
                }
            };

            query.QueryAsync();

            return(taskComplete.Task);
        }
Ejemplo n.º 23
0
        private void mipos_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                speechSynth.CancelAll();
                ReverseGeocodeQuery query = new ReverseGeocodeQuery()

                {
                    GeoCoordinate = new GeoCoordinate(lat, lon)
                };


                query.QueryCompleted += query_QueryCompleted;

                query.QueryAsync();
            }
            catch
            {
                error2();
            }
        }
Ejemplo n.º 24
0
        private async void GetGPSLocation()
        {
            try
            {
                prog.IsVisible       = true;
                prog.IsIndeterminate = true;
                prog.Text            = "Getting GPS location...";

                myGeoLocator = new Geolocator();
                myGeoLocator.DesiredAccuracy   = PositionAccuracy.High;
                myGeoLocator.MovementThreshold = 50;

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

                Latitude  = geoposition.Coordinate.Latitude;
                Longitude = geoposition.Coordinate.Longitude;

                var reverseGeocode = new ReverseGeocodeQuery();
                reverseGeocode.GeoCoordinate   = new GeoCoordinate(geoposition.Coordinate.Latitude, Longitude);
                reverseGeocode.QueryCompleted += ReverseGeocodeQueryCompleted;
                reverseGeocode.QueryAsync();
            }

            catch (UnauthorizedAccessException)
            {
                btnalert.IsEnabled = true;
                MessageBox.Show(AppResources.GPSDisabled);
            }
            catch (Exception)
            {
                btnalert.IsEnabled = true;
                MessageBox.Show(AppResources.GPSDisabled);
            }
            finally
            {
                btnalert.IsEnabled   = true;
                prog.IsVisible       = false;
                prog.IsIndeterminate = false;
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Gets current geocoordinate for use with Nokia Music API.
        /// </summary>
        private async void GetCurrentCoordinate()
        {
            Geolocator geolocator = new Geolocator();

            geolocator.DesiredAccuracy = PositionAccuracy.Default;

            try
            {
                Geoposition currentPosition = await geolocator.GetGeopositionAsync(
                    TimeSpan.FromMinutes(1),
                    TimeSpan.FromSeconds(10));

                Dispatcher.BeginInvoke(() =>
                {
                    GeoCoordinate coordinate = new GeoCoordinate(
                        currentPosition.Coordinate.Latitude,
                        currentPosition.Coordinate.Longitude);
                    ReverseGeocodeQuery reverseGeocodeQuery = new ReverseGeocodeQuery();
                    reverseGeocodeQuery.GeoCoordinate       = new GeoCoordinate(
                        coordinate.Latitude,
                        coordinate.Longitude);
                    reverseGeocodeQuery.QueryCompleted += ReverseGeocodeQuery_QueryCompleted;
                    reverseGeocodeQuery.QueryAsync();
                });
            }
            catch (Exception /*ex*/)
            {
                // Couldn't get current location. Location may be disabled.
                // Region info from the device is used as a fallback.
                MessageBox.Show("Current location cannot be obtained. It is "
                                + "recommended that location service is turned "
                                + "on in phone settings when using Music Explorer."
                                + "\n\nUsing region info from phone settings instead.");

                InitializeNokiaMusicApi(null);
            }
        }
Ejemplo n.º 26
0
        private void GetCurrentCoordinate()
        {
            Geolocator geolocator = new Geolocator();

            geolocator.DesiredAccuracy = PositionAccuracy.High;


            try
            {
                MyCoordinate = new GeoCoordinate(lat, longi);

                if (MyReverseGeocodeQuery == null || !MyReverseGeocodeQuery.IsBusy)
                {
                    MyReverseGeocodeQuery = new ReverseGeocodeQuery();
                    MyReverseGeocodeQuery.GeoCoordinate   = new GeoCoordinate(MyCoordinate.Latitude, MyCoordinate.Longitude);
                    MyReverseGeocodeQuery.QueryCompleted += ReverseGeocodeQuery_QueryCompleted;
                    MyReverseGeocodeQuery.QueryAsync();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Ejemplo n.º 27
0
        private async void GetCurrentCoordinate()
        {
            Geolocator geolocator = new Geolocator();

            geolocator.DesiredAccuracy = PositionAccuracy.High;

            try
            {
                Geoposition currentPosition = await geolocator.GetGeopositionAsync(TimeSpan.FromSeconds(20), TimeSpan.FromSeconds(10));

                _accuracy = currentPosition.Coordinate.Accuracy;

                MyCoordinate = new GeoCoordinate(currentPosition.Coordinate.Latitude, currentPosition.Coordinate.Longitude);

                if (MyReverseGeocodeQuery == null || !MyReverseGeocodeQuery.IsBusy)
                {
                    MyReverseGeocodeQuery = new ReverseGeocodeQuery();
                    MyReverseGeocodeQuery.GeoCoordinate   = new GeoCoordinate(MyCoordinate.Latitude, MyCoordinate.Longitude);
                    MyReverseGeocodeQuery.QueryCompleted += ReverseGeocodeQuery_QueryCompleted;
                    MyReverseGeocodeQuery.QueryAsync();
                }
            }
            catch { }
        }
Ejemplo n.º 28
0
        private void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs <GeoCoordinate> e)
        {
            ReverseGeocodeQuery query = new ReverseGeocodeQuery();

            query.GeoCoordinate   = new GeoCoordinate(e.Position.Location.Latitude, e.Position.Location.Longitude);
            query.QueryCompleted += (s, ee) =>
            {
                txtAddress.Visibility = System.Windows.Visibility.Visible;
                LayoutRoot.Opacity    = 1;
                pgrAddress.Visibility = System.Windows.Visibility.Collapsed;
                if (ee.Error == null && ee.Result.Count > 0)
                {
                    txtAddress.Text = AppResources.PhotoPage_Address + " " +
                                      ee.Result.First().Information.Address.District + " - " +
                                      ee.Result.First().Information.Address.City;
                }
                else
                {
                    txtAddress.Text = AppResources.PhotoPage_Address_Error;
                }
            };
            query.QueryAsync();
            watcher.Dispose();
        }
Ejemplo n.º 29
0
 // When the page is loaded, make sure that you have obtained the users consent to use their location
 protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
 {
     string sLatitude = "0.0";
     string sLongitude = "0.0";
     string sName = "";
     if (NavigationContext.QueryString.TryGetValue("Latitude", out sLatitude))
     {
     }
     if (NavigationContext.QueryString.TryGetValue("Longitude", out sLongitude))
     {
     }
     if (NavigationContext.QueryString.TryGetValue("Name", out sName))
     {
     }
     if ((sName + sLongitude + sLatitude) != "")
     {
         RouteLocation = new GeoCoordinate();
         RouteLocation.Latitude = double.Parse(sLatitude);
         RouteLocation.Longitude = double.Parse(sLongitude);
         RouteLocation.Altitude = 0.00;
         RouteAddress = new Address();
         RouteAddress.Latitude = RouteLocation.Latitude;
         RouteAddress.Longitude = RouteLocation.Longitude;
         RouteAddress.Address1 = sName;
         Destination.GeoCoordinate = RouteLocation;
         reverseQuery = new ReverseGeocodeQuery();
         reverseQuery.GeoCoordinate = RouteLocation;
         reverseQuery.QueryCompleted += reverseQuery_QueryCompleted;
         reverseQuery.QueryAsync();
         currentPoint = 0;
     }
 }
Ejemplo n.º 30
0
 private void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
 {
     ReverseGeocodeQuery query = new ReverseGeocodeQuery();
     query.GeoCoordinate = new GeoCoordinate(e.Position.Location.Latitude, e.Position.Location.Longitude);
     query.QueryCompleted += (s, ee) =>
     {
         txtAddress.Visibility = System.Windows.Visibility.Visible;
         LayoutRoot.Opacity = 1;
         pgrAddress.Visibility = System.Windows.Visibility.Collapsed;
         if (ee.Error == null && ee.Result.Count > 0)
         {
             txtAddress.Text = AppResources.PhotoPage_Address + " " +
                 ee.Result.First().Information.Address.District + " - " +
                 ee.Result.First().Information.Address.City;
         }
         else
         {
             txtAddress.Text = AppResources.PhotoPage_Address_Error;
         }
     };
     query.QueryAsync();
     watcher.Dispose();
 }
Ejemplo n.º 31
0
        /// <summary>
        /// Gets current geocoordinate for use with MixRadio API.
        /// </summary>
        private async void GetCurrentCoordinate()
        {
            Geolocator geolocator = new Geolocator();
            geolocator.DesiredAccuracy = PositionAccuracy.Default;

            try
            {
                Geoposition currentPosition = await geolocator.GetGeopositionAsync(
                    TimeSpan.FromMinutes(1),
                    TimeSpan.FromSeconds(10));

                Dispatcher.BeginInvoke(() =>
                {
                    GeoCoordinate coordinate = new GeoCoordinate(
                        currentPosition.Coordinate.Latitude, 
                        currentPosition.Coordinate.Longitude);
                    ReverseGeocodeQuery reverseGeocodeQuery = new ReverseGeocodeQuery();
                    reverseGeocodeQuery.GeoCoordinate = new GeoCoordinate(
                        coordinate.Latitude, 
                        coordinate.Longitude);
                    reverseGeocodeQuery.QueryCompleted += ReverseGeocodeQuery_QueryCompleted;
                    reverseGeocodeQuery.QueryAsync();
                });
            }
            catch (Exception /*ex*/)
            {
                // Couldn't get current location. Location may be disabled.
                // Region info from the device is used as a fallback.
                MessageBox.Show("Current location cannot be obtained. It is " 
                              + "recommended that location service is turned "
                              + "on in phone settings when using Music Explorer."
                              + "\n\nUsing region info from phone settings instead.");

                InitializeMixRadioApi(null);
            }
        }
        private void btnSelect_Click(object sender, EventArgs e)
        {
            if (selectedAddress == "")
            {
                ShowProgressIndicator("Getting address...");
                ReverseGeocodeQuery query = new ReverseGeocodeQuery()
                {
                    GeoCoordinate = selectedGeocoordinate
                };
                query.QueryCompleted += query_QueryCompleted;
                query.QueryAsync();

            }
            else
            {
                PhoneApplicationService.Current.State["location"] = selectedGeocoordinate;
                PhoneApplicationService.Current.State["address"] = selectedAddress;
                NavigationService.GoBack();
            }
        }
Ejemplo n.º 33
0
 /// <summary>
 /// Event handler for clicking a map marker. 
 /// Initiates reverse geocode query.
 /// </summary>
 private void Marker_Click(object sender, EventArgs e)
 {
     Polygon p = (Polygon)sender;
     GeoCoordinate geoCoordinate = (GeoCoordinate)p.Tag;
     if (MyReverseGeocodeQuery == null || !MyReverseGeocodeQuery.IsBusy)
     {
         MyReverseGeocodeQuery = new ReverseGeocodeQuery();
         MyReverseGeocodeQuery.GeoCoordinate = new GeoCoordinate(geoCoordinate.Latitude, geoCoordinate.Longitude);
         MyReverseGeocodeQuery.QueryCompleted += ReverseGeocodeQuery_QueryCompleted;
         MyReverseGeocodeQuery.QueryAsync();
     }
 }
Ejemplo n.º 34
0
        public async Task<String>  getCurrentLocation()
        {
             Debug.WriteLine("getCurrentLocation():- 1> Start");
            Geolocator geolocator = new Geolocator();
            geolocator.DesiredAccuracyInMeters = 50;
                     
            try
            {
                Debug.WriteLine("getCurrentLocation():- 1> await for current latlong");
                Geoposition geoposition = await geolocator.GetGeopositionAsync(
                    maximumAge: TimeSpan.FromMinutes(0.5),
                    timeout: TimeSpan.FromSeconds(5)
                    );
                Debug.WriteLine("getCurrentLocation():- 1> got the current latlong");
               // txtBlockLocation.Text = "Latitude:" + geoposition.Coordinate.Latitude.ToString("0.00") + " Longitude:" + geoposition.Coordinate.Longitude.ToString("0.00");

                LocationResult = new GeoCoordinate(geoposition.Coordinate.Latitude, geoposition.Coordinate.Longitude);

                if (MyReverseGeocodeQuery == null || !MyReverseGeocodeQuery.IsBusy)
                {
                    MyReverseGeocodeQuery = new ReverseGeocodeQuery();
                    MyReverseGeocodeQuery.GeoCoordinate = new GeoCoordinate(LocationResult.Latitude, LocationResult.Longitude);
                    MyReverseGeocodeQuery.QueryCompleted += ReverseGeocodeQuery_QueryCompleted;
                    Debug.WriteLine("getCurrentLocation():- 1> Start Reverse Geocoding");
                    MyReverseGeocodeQuery.QueryAsync();
                    Debug.WriteLine("getCurrentLocation():- 1> Completed Reverse Geocoding");
                    
                }
            }
            catch (Exception ex)
            {
                if ((uint)ex.HResult == 0x80004004)
                {
                    // the application does not have the right capability or the location master switch is off
                    txtBlockLocation.Text = txtBlockLocation.Text + "Status: " + "Location  is disabled in phone settings";
                }                
            }
            return "";
        }
Ejemplo n.º 35
0
 void speakInfoAboutLocation(GeoCoordinate geocord)
 {
     ReverseGeocodeQuery query = new ReverseGeocodeQuery();
     query.GeoCoordinate = geocord;
     query.QueryCompleted += query_QueryCompleted;
     query.QueryAsync();
 }
Ejemplo n.º 36
0
 private void ReverseGeocodeMyLocation()
 {
     if (MyCoordinate != null)
     {
         if (MyReverseGeocodeQuery == null || !MyReverseGeocodeQuery.IsBusy)
         {
             MyReverseGeocodeQuery = new ReverseGeocodeQuery();
             MyReverseGeocodeQuery.GeoCoordinate = new GeoCoordinate(MyCoordinate.Latitude, MyCoordinate.Latitude);
             MyReverseGeocodeQuery.QueryCompleted += MyReverseGeoCodeQueryCompleted;
             MyReverseGeocodeQuery.QueryAsync();
         }
     }
 }
Ejemplo n.º 37
0
        //Events
        private void GetLocationAddress(double latitude, double longitude)
        //Returns the users current location as a civic address
        {
            if (MyReverseGeocodeQueryOrigin == null || !MyReverseGeocodeQueryOrigin.IsBusy)
            {
                //progressBar.Visibility = Visibility.Visible;
                MyReverseGeocodeQueryOrigin = new ReverseGeocodeQuery();
                MyReverseGeocodeQueryOrigin.GeoCoordinate = new GeoCoordinate(latitude, longitude);
                MyReverseGeocodeQueryOrigin.QueryCompleted += CurrentLocationReverseGeocodeQuery_QC;
                MyReverseGeocodeQueryOrigin.QueryAsync();

            }
        }
Ejemplo n.º 38
0
        private async void FSLocationButton_Click(object sender, System.Windows.Input.GestureEventArgs e)
        {
            //Check for the user agreement in use his position. If not, method returns.
            if ((bool)IsolatedStorageSettings.ApplicationSettings["LocationConsent"] != true)
            {
                // The user has opted out of Location.
                return;
            }

            //Declare and Inizialize a Geolocator object
            Geolocator geolocator = new Geolocator();
            //Set his accuracy in Meters 
            geolocator.DesiredAccuracyInMeters = 50;
            
            //Let's get the position of the user. Since there is the possibility of getting an Exception, this method is called inside a try block
            try
            {
                textBlock1.Text = "searching...";
                //The await guarantee the calls  to be returned on the thread from which they were called
                //Since it is call directly from the UI thread, the code is able to access and modify the UI directly when the call returns.
                Geoposition geoposition = await geolocator.GetGeopositionAsync(
                    maximumAge: TimeSpan.FromMinutes(5),
                    timeout: TimeSpan.FromSeconds(10)
                    );

                
                //With this 2 lines of code, the app is able to write on a Text Label the Latitude and the Longitude, given by Geoposition

                MyCoordinate.Latitude = geoposition.Coordinate.Latitude;
                MyCoordinate.Longitude = geoposition.Coordinate.Longitude;
                


                ShowMyLocationOnTheMap();

               

                if (MyReverseGeocodeQuery == null || !MyReverseGeocodeQuery.IsBusy)
                {
                    MyReverseGeocodeQuery = new ReverseGeocodeQuery();
                    MyReverseGeocodeQuery.GeoCoordinate = new GeoCoordinate(MyCoordinate.Latitude, MyCoordinate.Longitude);
                    MyReverseGeocodeQuery.QueryCompleted += ReverseGeocodeQuery_QueryCompleted;
                    MyReverseGeocodeQuery.QueryAsync();
                }
                
                //StatusTextBlock.Text = "Status = This is your position :)";
            }
            //If an error is catch 2 are the main causes: the first is that you forgot to includ ID_CAP_LOCATION in your app manifest. 
            //The second is that the user doesn't turned on the Location Services
            catch (Exception ex)
            {
                if ((uint)ex.HResult == 0x80004004)
                {
                    //StatusTextBlock.Text = "Status= Location  is disabled in phone settings.";
                }
                //else
                {
                    // something else happened during the acquisition of the location
                }
            }
        }
Ejemplo n.º 39
0
        private void XAMLMap_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            /*
            if (!isMapFocused)
            {
                XAMLMap.Height = 525;
                XAMLMap.Margin = new Thickness(0, -130, 0, 0);
                isMapFocused = true;
            }
            */
            XAMLMap.Focus();
            MyCoordinates[1] = XAMLMap.ConvertViewportPointToGeoCoordinate(e.GetPosition(XAMLMap));
            DrawMapMarkers();

            distanceLeft = MyCoordinates[0].GetDistanceTo(MyCoordinates[1]) * 0.000621371; // distance calculator in meters, converted to miles
            DistanceLeftDistanceTextBlock.Text = distanceLeft.ToString("0.00");

            ReverseGeocodeQuery query = new ReverseGeocodeQuery()
            {
                GeoCoordinate = MyCoordinates[1]
            };
            query.QueryCompleted += query_QueryCompleted;
            query.QueryAsync();
        }