Esempio n. 1
0
        string ResolveAddressSync()
        {
            string Location;
            GeoCoordinateWatcher watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);

            watcher.MovementThreshold = 1.0; // set to one meter
            watcher.TryStart(false, TimeSpan.FromMilliseconds(1000));

            CivicAddressResolver resolver = new CivicAddressResolver();

            if (watcher.Position.Location.IsUnknown == false)
            {
                CivicAddress address = resolver.ResolveAddress(watcher.Position.Location);

                if (!address.IsUnknown)
                {
                    Location = $"Country:{address.CountryRegion}, City: {address.City}";
                    return(_location = Location);
                }
                else
                {
                    Location = "Address unknown.";
                    return(_location = Location);
                }
            }
            else
            {
                Location = "Address unknown.";
                return(_location = Location);
            }
        }
Esempio n. 2
0
        public void addressResolution(GeoCoordinate watcher)
        {
            CivicAddressResolver resolver = new CivicAddressResolver();
            CivicAddress         address  = resolver.ResolveAddress(watcher);

            TestBlock.Text = address.AddressLine1;
        }
//<Snippet2>
        static void ResolveAddressSync()
        {
            GeoCoordinateWatcher watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);

            watcher.MovementThreshold = 1.0; // set to one meter
            watcher.TryStart(false, TimeSpan.FromMilliseconds(1000));

            CivicAddressResolver resolver = new CivicAddressResolver();

            if (watcher.Position.Location.IsUnknown == false)
            {
                CivicAddress address = resolver.ResolveAddress(watcher.Position.Location);

                if (!address.IsUnknown)
                {
                    Console.WriteLine("Country: {0}, Zip: {1}",
                                      address.CountryRegion,
                                      address.PostalCode);
                }
                else
                {
                    Console.WriteLine("Address unknown.");
                }
            }
        }
Esempio n. 4
0
        void UpdateCoordinate(GeoCoordinate geo)
        {
            InfoText.Text = geo.ToString();
            ICivicAddressResolver resolver = new CivicAddressResolver();
            var address = resolver.ResolveAddress(geo);

            InfoText.Text += address.City;
        }
Esempio n. 5
0
        public string RetornaEnderecoOrigem(double lat, double lon)
        {
            var resolver = new CivicAddressResolver();
            var coord    = new GeoCoordinate(lat, lon);
            var address  = resolver.ResolveAddress(coord);

            return(address.AddressLine1);
        }
Esempio n. 6
0
 public DevicePositioning()
 {
     _location = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
     //
     _location.MovementThreshold = 1.0;//1米
     _location.PositionChanged  += Location_PositionChanged;
     //
     _address = new CivicAddressResolver();
     _address.ResolveAddressCompleted += Address_ResolveAddressCompleted;
 }
Esempio n. 7
0
        private static void PrintWhereIAm()
        {
            var resolver = new CivicAddressResolver();
            var address  = resolver.ResolveAddress(
                new GeoCoordinate()
            {
                Latitude  = 44.9636674186754,
                Longitude = -93.267997741
            });

            Console.Out.WriteLine(address);
        }
        private void ResolveCivilAddress(GeoCoordinate location)
        {
            var resolver = new CivicAddressResolver();
            var address  = resolver.ResolveAddress(location);

            if (!address.IsUnknown)
            {
                var civilAddress = $"{address.CountryRegion}, {address.City}";

                _addressCompletionSource.SetResult(civilAddress);
            }
            else
            {
                _addressCompletionSource.SetException(new UnknownAddressException());
            }
        }
Esempio n. 9
0
        private async Task <AsyncResult <Tuple <CivicAddress, GeoCoordinate> > > TryLookupInternal()
        {
            // Check if we've already looked up the location.
            if (_coordinates != null && _address != null)
            {
                if (!_coordinates.IsUnknown && !_address.IsUnknown)
                {
                    return(new AsyncResult <Tuple <CivicAddress, GeoCoordinate> >(true, new Tuple <CivicAddress, GeoCoordinate>(_address, _coordinates)));
                }
            }

            TaskCompletionSource <GeoCoordinate> tcs = new TaskCompletionSource <GeoCoordinate>();

            _gps.PositionChanged += (sender, args) =>
            {
                // Need to stop the GPS ASAP otherwise it might trigger again.
                _gps.Stop();

                if (!tcs.TrySetResult(args.Position.Location))
                {
                    _gps.Start(suppressPermissionPrompt: true);
                }
            };

            try
            {
                _gps.Start(suppressPermissionPrompt: true);

                using (var cts = new CancellationTokenSource(10000))
                {
                    _coordinates = await tcs.Task.WaitAsync(cts.Token);

                    CivicAddressResolver resolver = new CivicAddressResolver();
                    _address = resolver.ResolveAddress(_coordinates);

                    return(new AsyncResult <Tuple <CivicAddress, GeoCoordinate> >(true, new Tuple <CivicAddress, GeoCoordinate>(_address, _coordinates)));
                }
            }
            catch (TaskCanceledException)
            {
                return(new AsyncResult <Tuple <CivicAddress, GeoCoordinate> >(false, null));
            }
            finally
            {
                _gps.Stop();
            }
        }
Esempio n. 10
0
        private bool TryGPSLookupInternal(out GeoCoordinate coordinates, out CivicAddress address)
        {
            // Check if we've already looked up the location.
            if (_coordinates != null && _address != null)
            {
                if (!_coordinates.IsUnknown && !_address.IsUnknown)
                {
                    coordinates = _coordinates;
                    address     = _address;
                    return(true);
                }
            }

            TaskCompletionSource <GeoCoordinate> tcs = new TaskCompletionSource <GeoCoordinate>();

            _gps.PositionChanged += (sender, args) =>
            {
                // Need to stop the GPS ASAP otherwise it might trigger again.
                _gps.Stop();

                if (!tcs.TrySetResult(args.Position.Location))
                {
                    _gps.Start(suppressPermissionPrompt: true);
                }
            };

            _gps.Start(suppressPermissionPrompt: true);

            if (tcs.Task.Wait(10000)) // 10 seconds.
            {
                _coordinates = tcs.Task.Result;

                CivicAddressResolver resolver = new CivicAddressResolver();
                _address = resolver.ResolveAddress(_coordinates);

                coordinates = _coordinates;
                address     = _address;
                return(true);
            }

            _gps.Stop();

            coordinates = null;
            address     = null;
            return(false);
        }
Esempio n. 11
0
        //<snippet2>
        static void ResolveAddressAsync()
        {
            GeoCoordinateWatcher watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
            bool started = false;

            watcher.MovementThreshold = 1.0; // set to one meter
            started = watcher.TryStart(false, TimeSpan.FromMilliseconds(1000));

            if (started)
            {
                CivicAddressResolver resolver = new CivicAddressResolver();

                resolver.ResolveAddressCompleted += new EventHandler <ResolveAddressCompletedEventArgs>(resolver_ResolveAddressCompleted);

                if (watcher.Position.Location.IsUnknown == false)
                {
                    resolver.ResolveAddressAsync(watcher.Position.Location);
                }
            }
        }
Esempio n. 12
0
        private string[] GetCurrentLocationString(GeoCoordinate geoCoordinate)
        {
            if (geoCoordinate == null)
            {
                return(null);
            }

            if (currentGeoLocation == geoCoordinate && cachedAddress != null)
            {
                return(cachedAddress);
            }

            CivicAddressResolver resolver = new CivicAddressResolver();
            var address = resolver.ResolveAddress(geoCoordinate);

            if (address.IsUnknown)
            {
                cachedAddress = null;
                return(cachedAddress);
            }

            cachedAddress = BuildAddressString(address);
            return(cachedAddress);
        }
Esempio n. 13
0
 void UpdateCoordinate(GeoCoordinate geo)
 {
     InfoText.Text = geo.ToString();
     ICivicAddressResolver resolver = new CivicAddressResolver();
     var address = resolver.ResolveAddress(geo);
     InfoText.Text += address.City;
 }
Esempio n. 14
0
    private bool TryGPSLookupInternal(out GeoCoordinate coordinates, out CivicAddress address)
    {
      // Check if we've already looked up the location.
      if (_coordinates != null && _address != null)
      {
        if (!_coordinates.IsUnknown && !_address.IsUnknown)
        {
          coordinates = _coordinates;
          address = _address;
          return true;
        }
      }

      TaskCompletionSource<GeoCoordinate> tcs = new TaskCompletionSource<GeoCoordinate>();

      _gps.PositionChanged += (sender, args) =>
        {
          // Need to stop the GPS ASAP otherwise it might trigger again.
          _gps.Stop();

          if (!tcs.TrySetResult(args.Position.Location))
            _gps.Start(suppressPermissionPrompt: true);
        };

      _gps.Start(suppressPermissionPrompt: true);

      if (tcs.Task.Wait(10000)) // 10 seconds.
      {
        _coordinates = tcs.Task.Result;

        CivicAddressResolver resolver = new CivicAddressResolver();
        _address = resolver.ResolveAddress(_coordinates);

        coordinates = _coordinates;
        address = _address;
        return true;
      }

      _gps.Stop();

      coordinates = null;
      address = null;
      return false;
    }
        public void ConvertLocation(GeoCoordinate location)
        {
            Debug.WriteLine("ConvertLocation");
            // converts a point to an address
            Debug.WriteLine("ConvertLocation" );
            Debug.WriteLine("GeoCoordinate:" + location.ToString());
            CivicAddressResolver resolver = new CivicAddressResolver();
            CivicAddress d = new CivicAddress();
            if (location.IsUnknown == false)
            {
                CivicAddress address = resolver.ResolveAddress(location);
                Debug.WriteLine("CivicAddress:" + address.ToString());

                if (!address.IsUnknown)
                {
                    Debug.WriteLine("Country: {0}, Zip: {1}",
                            address.CountryRegion,
                            address.PostalCode);
                }
                else
                {
                    Debug.WriteLine("Address unknown.");
                }
            }
        }
Esempio n. 16
0
        private string[] GetCurrentLocationString(GeoCoordinate geoCoordinate)
        {
            if (geoCoordinate == null)
                return null;

            if (currentGeoLocation == geoCoordinate && cachedAddress != null)
                return cachedAddress;

            CivicAddressResolver resolver = new CivicAddressResolver();
            var address = resolver.ResolveAddress(geoCoordinate);

            if (address.IsUnknown)
            {
                cachedAddress = null;
                return cachedAddress;
            }

            cachedAddress = BuildAddressString(address);
            return cachedAddress;
        }