Example #1
0
        public Address GetAddress(LatLng locate)
        {
            Geocoder        geocoder = new Geocoder(Instance, Locale.Default);
            IList <Address> address  = geocoder.GetFromLocation(locate.Latitude, locate.Longitude, 1);

            return(address[0]);
        }
Example #2
0
        public Task <string> GetAddressFromCoordinate(double lat, double lng)
        {
            var tcs      = new TaskCompletionSource <string>();
            var context  = Mvx.Resolve <IDroidService>().CurrentContext;
            var geocoder = new Geocoder(context, Locale.Default);

            try
            {
                var addresses = geocoder.GetFromLocation(lat, lng, 1);

                if (addresses != null && addresses.Count > 0)
                {
                    var address    = addresses[0].GetAddressLine(0);
                    var city       = addresses[0].Locality;
                    var state      = addresses[0].AdminArea;
                    var country    = addresses[0].CountryName;
                    var postalCode = addresses[0].PostalCode;
                    var knownName  = addresses[0].FeatureName;

                    // locationTxt.setText(address + " " + city + " " + country);
                    // return address + ", " + city + ", " + state;

                    tcs.SetResult(city + ", " + state);
                    return(tcs.Task);
                }
            }
            catch (IOException e)
            {
                e.PrintStackTrace();
            }


            tcs.SetResult("");
            return(tcs.Task);
        }
Example #3
0
        public static Address GetAddress(Context Ctx, double Lat, double Long)
        {
            Geocoder        GCoder   = new Geocoder(Ctx);
            IList <Address> AddrList = GCoder.GetFromLocation(Lat, Long, 10);

            return(AddrList.FirstOrDefault());
        }
Example #4
0
        public void OnLocationChanged(Location location)
        {
            try {
                _currentLocation = location;

                if (_currentLocation == null)
                {
                    _location = "Unable to determine your location.";
                }
                else
                {
                    _location = String.Format("{0},{1}", _currentLocation.Latitude, _currentLocation.Longitude);

                    Geocoder geocoder = new Geocoder(this);

                    //The Geocoder class retrieves a list of address from Google over the internet
                    IList <Address> addressList = geocoder.GetFromLocation(_currentLocation.Latitude, _currentLocation.Longitude, 10);

                    Address addressCurrent = addressList.FirstOrDefault();

                    if (addressCurrent != null)
                    {
                        StringBuilder deviceAddress = new StringBuilder();

                        for (int i = 0; i < addressCurrent.MaxAddressLineIndex; i++)
                        {
                            deviceAddress.Append(addressCurrent.GetAddressLine(i))
                            .AppendLine(",");
                        }

                        _address = deviceAddress.ToString();
                    }
                    else
                    {
                        _address = "Unable to determine the address.";
                    }

                    IList <Address> source        = geocoder.GetFromLocationName(_sourceAddress, 1);
                    Address         addressOrigin = source.FirstOrDefault();

                    var coord1 = new LatLng(addressOrigin.Latitude, addressOrigin.Longitude);
                    var coord2 = new LatLng(addressCurrent.Latitude, addressCurrent.Longitude);

                    var distanceInRadius = Utils.HaversineDistance(coord1, coord2, Utils.DistanceUnit.Miles);

                    _remarks = string.Format("Your are {0} miles away from your original location.", distanceInRadius);

                    Intent intent = new Intent(this, typeof(GPSServiceReciever));
                    intent.SetAction(GPSServiceReciever.LOCATION_UPDATED);
                    intent.AddCategory(Intent.CategoryDefault);
                    intent.PutExtra("Location", _location);
                    intent.PutExtra("Address", _address);
                    intent.PutExtra("Remarks", _remarks);
                    SendBroadcast(intent);
                }
            }
            catch (Exception ex) {
                _address = "Unable to determine the address.";
            }
        }
Example #5
0
        public static string GetAddress(Activity instance)
        {
            string address = string.Empty;

            try
            {
                Geocoder geocoder = new Geocoder(instance);

                IList <Address> addressList = geocoder.GetFromLocation(StartLocation.Latitude, StartLocation.Longitude, 1);

                Address addressCurrent = addressList.FirstOrDefault();

                if (addressCurrent != null)
                {
                    StringBuilder deviceAddress = new StringBuilder();

                    for (int i = 0; i <= addressCurrent.MaxAddressLineIndex; i++)
                    {
                        if (addressCurrent.GetAddressLine(i).Length > 0)
                        {
                            deviceAddress.Append(addressCurrent.GetAddressLine(i)).AppendLine(",");
                        }
                    }

                    address = deviceAddress.ToString().Replace(System.Environment.NewLine, string.Empty).TrimEnd(',') + ".";
                }
            }
            catch
            {
                address = "Can't get address. Are you online?";
            }

            StartAddress = address;
            return(address);
        }
 public void OnLocationChanged(Location location)
 {
     try {
         Geocoder        geocoder    = new Geocoder(this);
         IList <Address> addressList = geocoder.GetFromLocation(location.Latitude, location.Longitude, 5);
         Address         address     = addressList.FirstOrDefault();
         if (address != null)
         {
             if (address.FeatureName == address.Thoroughfare)
             {
                 var deviceAddress = address.FeatureName + ", " + address.Locality + ", " + address.AdminArea + ", " + address.CountryCode + ", " + address.PostalCode;
                 addressToSend = deviceAddress;
             }
             else
             {
                 var deviceAddress = address.FeatureName + " " + address.Thoroughfare + ", " + address.Locality + ", " + address.AdminArea + ", " + address.CountryCode + ", " + address.PostalCode;
                 addressToSend = deviceAddress;
             }
         }
         else
         {
             addressToSend = "Address not found.";
         }
     }
     catch {
         addressToSend = "unknown error";
     }
 }
Example #7
0
        public void OnLocationChanged(Location location)
        {
            locationText.Text = String.Format("{0} {1}", location.Latitude, location.Longitude);
            Geocoder        geocoder    = new Geocoder(this);
            IList <Address> addressList = geocoder.GetFromLocation(location.Latitude, location.Longitude, 5);
            Address         address     = addressList.FirstOrDefault();

            if (address != null)
            {
                if (address.FeatureName == address.Thoroughfare)
                {
                    var deviceAddress = address.FeatureName + ", " + address.Locality + ", " + address.AdminArea + ", " + address.CountryCode + ", " + address.PostalCode;
                    addressText.Text = deviceAddress;
                }
                else
                {
                    var deviceAddress = address.FeatureName + " " + address.Thoroughfare + ", " + address.Locality + ", " + address.AdminArea + ", " + address.CountryCode + ", " + address.PostalCode;
                    addressText.Text = deviceAddress;
                }
            }
            else
            {
                addressText.Text = "Lat and Long found, but Address not found.";
            }
        }
Example #8
0
        public void pegarAsync(float latitude, float longitude, GeoEnderecoEventHandler callback)
        {
            new Thread(new ThreadStart(() => {
                try
                {
                    Context context = Android.App.Application.Context;
                    var geo         = new Geocoder(context);
                    var addresses   = geo.GetFromLocation(latitude, longitude, 1);

                    var geoEndereco = addresses.Take(1).SingleOrDefault();
                    if (geoEndereco != null)
                    {
                        var endereco = new GeoEnderecoInfo
                        {
                            Logradouro  = geoEndereco.Thoroughfare,
                            Complemento = geoEndereco.SubThoroughfare,
                            Bairro      = geoEndereco.SubLocality,
                            Cidade      = geoEndereco.Locality,
                            Uf          = geoEndereco.AdminArea,
                            CEP         = geoEndereco.PostalCode,
                        };
                        if (callback != null)
                        {
                            CurrentActivityUtils.Current.RunOnUiThread(() =>
                            {
                                callback(null, new GeoEnderecoEventArgs(endereco));
                            });
                        }
                    }
                }
                catch (Exception e) {
                    // não faz nada
                }
            })).Start();
        }
        public void OnLocationChanged(Location location)
        {
            _builder.AppendLine(
                string.Format("Location updated, lat: {0}, long: {1}",
                              location.Latitude, location.Longitude)
                );

            try
            {
                Address address =
                    _geocoder
                    .GetFromLocation(location.Latitude, location.Longitude, 1)
                    .FirstOrDefault();

                if (address != null)
                {
                    _builder.AppendLine(" -> " + address.CountryName);
                }
            }
            catch (IOException io)
            {
                Android.Util.Log.Debug("LocationActivity", io.Message);
            }

            _locationText.Text = _builder.ToString();
        }
Example #10
0
        public IList <TrackLocation> GenerateListOfTrackLocations(Coordinate currentLocation, Geocoder geocoder)
        {
            var listAddresses = geocoder.GetFromLocation(currentLocation.Latitude, currentLocation.Longitude, 30);
            IList <TrackLocation> returnList = new List <TrackLocation>();

            returnList.Add(new TrackLocation
            {
                Latitude  = currentLocation.Latitude,
                Longitude = currentLocation.Longitude
            });

            foreach (var address in listAddresses)
            {
                returnList.Add(new TrackLocation
                {
                    City        = address.Locality,
                    Country     = address.CountryName,
                    PostalCode  = address.PostalCode,
                    Street      = address.Thoroughfare,
                    HouseNumber = address.FeatureName,
                    Latitude    = address.Latitude,
                    Longitude   = address.Longitude
                });
            }

            return(returnList);
        }
Example #11
0
        async void AddressButton_OnClick(object sender, EventArgs eventArgs)
        {
            if (_currentLocation == null)
            {
                _addressText.Text = "Can't determine the current address.";
                return;
            }

            Geocoder        geocoder    = new Geocoder(this);
            IList <Address> addressList = geocoder.GetFromLocation(_currentLocation.Latitude, _currentLocation.Longitude, 10);

            Address address = addressList.FirstOrDefault();

            if (address != null)
            {
                StringBuilder deviceAddress = new StringBuilder();
                for (int i = 0; i < address.MaxAddressLineIndex; i++)
                {
                    deviceAddress.Append(address.GetAddressLine(i))
                    .AppendLine(",");
                }
                _addressText.Text = deviceAddress.ToString();
            }
            else
            {
                _addressText.Text = "Unable to determine the address.";
            }
        }
        protected override void OnHandleIntent(Android.Content.Intent intent)
        {
            var errorMessage = string.Empty;

            mReceiver = intent.GetParcelableExtra(Constants.Receiver) as ResultReceiver;

            if (mReceiver == null)
            {
                Log.Wtf(TAG, "No receiver received. There is nowhere to send the results.");
                return;
            }

            var location = (Location)intent.GetParcelableExtra(Constants.LocationDataExtra);

            if (location == null)
            {
                errorMessage = GetString(Resource.String.no_location_data_provided);
                Log.Wtf(TAG, errorMessage);
                DeliverResultToReceiver(Result.FirstUser, errorMessage);
                return;
            }

            var geocoder = new Geocoder(this, Java.Util.Locale.Default);

            List <Address> addresses = null;

            try {
                addresses = new List <Address> (geocoder.GetFromLocation(location.Latitude, location.Longitude, 1));
            } catch (IOException ioException) {
                errorMessage = GetString(Resource.String.service_not_available);
                Log.Error(TAG, errorMessage, ioException);
            } catch (IllegalArgumentException illegalArgumentException) {
                errorMessage = GetString(Resource.String.invalid_lat_long_used);
                Log.Error(TAG, string.Format("{0}. Latitude = {1}, Longitude = {2}", errorMessage,
                                             location.Latitude, location.Longitude), illegalArgumentException);
            }

            if (addresses == null || addresses.Count == 0)
            {
                if (string.IsNullOrEmpty(errorMessage))
                {
                    errorMessage = GetString(Resource.String.no_address_found);
                    Log.Error(TAG, errorMessage);
                }
                DeliverResultToReceiver(Result.FirstUser, errorMessage);
            }
            else
            {
                Address address          = addresses.FirstOrDefault();
                var     addressFragments = new List <string> ();

                for (int i = 0; i < address.MaxAddressLineIndex; i++)
                {
                    addressFragments.Add(address.GetAddressLine(i));
                }
                Log.Info(TAG, GetString(Resource.String.address_found));
                DeliverResultToReceiver(Result.Canceled, string.Join("\n", addressFragments));
            }
        }
Example #13
0
        public void OnLocationChanged(Location location)
        {
            try
            {
                currentLocation = location;
                if (currentLocation == null)
                {
                    Toast.MakeText(ApplicationContext, "Ubicación no encontrada. error al cargar latitud y longitud.", ToastLength.Long).Show();
                }
                else
                {
                    guardaLatitud  = currentLocation.Latitude.ToString();
                    guardaLongitud = currentLocation.Longitude.ToString();
                    lati           = string.Format("{0:N2}", Math.Truncate(currentLocation.Latitude * 100) / 100);
                    longi          = string.Format("{0:N2}", Math.Truncate(currentLocation.Longitude * 100) / 100);

                    Geocoder geocoder = new Geocoder(this);

                    IList <Address> addressList = geocoder.GetFromLocation(currentLocation.Latitude, currentLocation.Longitude, 5);

                    Address address = addressList.FirstOrDefault();

                    //Coordenadas de Trafalgar (51.50, -0.13):
                    double lat1     = currentLocation.Latitude;
                    double theta    = currentLocation.Longitude - (-0.13);
                    double distance = Math.Sin(Math.PI / 180.0 * (lat1))
                                      * Math.Sin(Math.PI / 180.0 * (51.50)) +
                                      Math.Cos(Math.PI / 180.0 * (lat1)) *
                                      Math.Cos(Math.PI / 180.0 * (51.50)) *
                                      Math.Cos(Math.PI / 180.0 * (theta));
                    distance = Math.Acos(distance);
                    distance = distance / Math.PI * 180.0;
                    distance = distance * 60 * 1.15;

                    distancia = distance * 1.609d; //lo pasa a kilometros

                    if (address != null)
                    {
                        //Al final lo he tenido que poner asi si no, no encontraba la direccion
                        string dir = address.GetAddressLine(0) + " " + address.GetAddressLine(1) + " " + address.GetAddressLine(2);
                        txtAddress.Text = dir;
                        direccion       = dir;
                    }
                    else
                    {
                        txtAddress.Text = "Direccion no encontrada";
                        direccion       = "Direccion no encontrada";
                        Toast.MakeText(ApplicationContext, "Dirección no encontrada. error al cargar la dirección.", ToastLength.Long).Show();
                    }
                }
            }
            catch (Exception ex)
            {
                txtAddress.Text = "Direccion no encontrada y " + ex.Message;
                direccion       = "Direccion no encontrada";
                Toast.MakeText(ApplicationContext, ex.ToString(), ToastLength.Long).Show();
            }
        }
Example #14
0
        public void OnLocationChanged(Location location)
        {
            Intent intent = new Intent();

            try
            {
                currentLocation = location;

                if (currentLocation == null)
                {
                    mensagem = "Endereço não encontrado. Tente novamente, por favor.";
                }
                else
                {
                    locationText = String.Format("{0},{1}", currentLocation.Latitude, currentLocation.Longitude);

                    Geocoder geocoder = new Geocoder(this.Activity);

                    IList <Address> adressList = geocoder.GetFromLocation(currentLocation.Latitude, currentLocation.Longitude, 10);
                    Address         adress     = adressList.FirstOrDefault();

                    if (adress != null)
                    {
                        StringBuilder deviceAdress = new StringBuilder();

                        for (int i = 0; i < adress.MaxAddressLineIndex; i++)
                        {
                            deviceAdress.Append(adress.GetAddressLine(i)).AppendLine(",");
                        }

                        endereco  = deviceAdress.ToString();
                        latitude  = adress.Latitude.ToString();
                        longitude = adress.Longitude.ToString();

                        intent.PutExtra("Lat", adress.Latitude.ToString());
                        intent.PutExtra("Lon", adress.Longitude.ToString());
                        intent.PutExtra("Endereco", endereco);
                        //SetResult(Result.FirstUser, intent);
                        Dismiss();
                    }
                    else
                    {
                        mensagem = "Endereço não encontrado. Tente novamente, por favor.";
                        intent.PutExtra("mensagem", mensagem);
                        //SetResult(Result.FirstUser, intent);
                        Dismiss();
                    }
                }
            }
            catch
            {
                mensagem = "Endereço não encontrado. Tente novamente, por favor.";
                intent.PutExtra("mensagem", mensagem);
                Dismiss();
            }
        }
Example #15
0
        public Address GetAddress()
        {
            locMgr = context.GetSystemService(Context.LocationService) as LocationManager;
            Criteria         criteria    = new Criteria();
            LocationProvider provider    = locMgr.GetProvider("network");
            Location         location    = locMgr.GetLastKnownLocation(provider.Name);
            Geocoder         geoc        = new Geocoder(context);
            IList <Address>  addressList = geoc.GetFromLocation(location.Latitude, location.Longitude, 10);
            Address          address     = addressList.FirstOrDefault();

            return(address);
        }
Example #16
0
        public void OnLocationChanged(Location location)
        {
            try
            {
                _currentLocation = location;

                if (_currentLocation == null)
                {
                    _location = "Unable to determine your location.";
                }
                else
                {
                    _location = String.Format("{0};{1}", _currentLocation.Latitude, _currentLocation.Longitude);

                    Geocoder geocoder = new Geocoder(this);

                    //The Geocoder class retrieves a list of address from Google over the internet
                    IList <Address> addressList = geocoder.GetFromLocation(_currentLocation.Latitude, _currentLocation.Longitude, 10);

                    Address addressCurrent = addressList.FirstOrDefault();

                    if (addressCurrent != null)
                    {
                        StringBuilder deviceAddress = new StringBuilder();

                        for (int i = 0; i < addressCurrent.MaxAddressLineIndex + 1; i++)
                        {
                            deviceAddress.Append(addressCurrent.GetAddressLine(i))
                            .AppendLine(",");
                        }

                        _address = deviceAddress.ToString();
                    }
                    else
                    {
                        _address = "Unable to determine the address.";
                    }

                    Intent intent = new Intent(this, typeof(HomeFragment.GPSServiceReciever));
                    intent.SetAction(HomeFragment.GPSServiceReciever.LOCATION_UPDATED);
                    intent.AddCategory(Intent.CategoryDefault);
                    intent.PutExtra("Location", _location);
                    intent.PutExtra("Address", _address);
                    intent.PutExtra("Latitude", _currentLocation.Latitude);
                    intent.PutExtra("Longitude", _currentLocation.Longitude);
                    SendBroadcast(intent);
                }
            }
            catch (Exception ex)
            {
                _address = "Unable to determine the address.";
            }
        }
Example #17
0
        //ILocationListener methods
        public void OnLocationChanged(Location location)
        {
            try {
                _currentLocation = location;

                if (_currentLocation == null)
                {
                    _locationText.Text = "Unable to determine your location.";
                }
                else
                {
                    _locationText.Text = String.Format("{0},{1}", _currentLocation.Latitude, _currentLocation.Longitude);

                    Geocoder geocoder = new Geocoder(this);

                    //The Geocoder class retrieves a list of address from Google over the internet
                    IList <Address> addressList = geocoder.GetFromLocation(_currentLocation.Latitude, _currentLocation.Longitude, 10);

                    Address addressCurrent = addressList.FirstOrDefault();

                    if (addressCurrent != null)
                    {
                        StringBuilder deviceAddress = new StringBuilder();

                        for (int i = 0; i < addressCurrent.MaxAddressLineIndex; i++)
                        {
                            deviceAddress.Append(addressCurrent.GetAddressLine(i))
                            .AppendLine(",");
                        }

                        _addressText.Text = deviceAddress.ToString();
                    }
                    else
                    {
                        _addressText.Text = "Unable to determine the address.";
                    }

                    IList <Address> source        = geocoder.GetFromLocationName(_sourceAddress, 1);
                    Address         addressOrigin = source.FirstOrDefault();

                    var coord1 = new LatLng(addressOrigin.Latitude, addressOrigin.Longitude);
                    var coord2 = new LatLng(addressCurrent.Latitude, addressCurrent.Longitude);

                    var distance = Utils.HaversineDistance(coord1, coord2, Utils.DistanceUnit.Miles);

                    _remarksText.Text = string.Format("Your are {0} miles away from your original location.", distance);
                }
            }
            catch {
                _addressText.Text = "Unable to determine the address.";
            }
        }
 private void GetCityByGeoLocation(Context cntxt)
 {
     try
     {
         Geocoder coder   = new Geocoder(cntxt, Java.Util.Locale.English);
         var      results = coder.GetFromLocation(-17.713371, 178.065033, 10);
         var      addr    = results.FirstOrDefault();
         if (addr != null)
         {
             string city = !string.IsNullOrEmpty(addr.Locality) ? addr.Locality : addr.FeatureName;
         }
     }
     catch { }
 }
        private void CreateAddressTextAndRefreshAddressRow(Location location)
        {
            Geocoder        geocoder  = new Geocoder(Activity);
            IList <Address> addresses = null;

            try
            {
                addresses = geocoder.GetFromLocation(location.Latitude, location.Longitude, 1);
            }
            catch (Exception ex)
            {
            }


            string wholeAddress = "";

            if (addresses != null)
            {
                try
                {
                    var dd = addresses[0];
                    wholeAddress = dd.Thoroughfare + " " + dd.SubThoroughfare;
                    wholeAddress = wholeAddress + System.Environment.NewLine + (dd.SubLocality + ", " ?? string.Empty) + dd.Locality;
                }
                catch (ArgumentOutOfRangeException aoore)
                {
                }
            }

            /*
             * try
             * {
             *    wholeAddress = addresses[0].GetAddressLine(0);
             * }
             * catch (System.ArgumentOutOfRangeException aoore)
             * {
             * }
             */

            if (wholeAddress.Length > 0)
            {
                Henspe.Current.addressText = wholeAddress;
            }
            else
            {
                Henspe.Current.addressText = Henspe.Current.unknownAddress;
            }

            //    RefreshRow(5);
        }
        private Address ReverseGeocodeCurrentLocation()
        {
            try
            {
                Geocoder        geocoder    = new Geocoder(this);
                IList <Address> addressList = geocoder.GetFromLocation(_currentLocation.Latitude, _currentLocation.Longitude, 10);

                Address address = addressList.FirstOrDefault();
                return(address);
            }catch (Exception ex)
            {
                return(null);
            }
        }
Example #21
0
        public String GetCity(double?lat, double?lng)
        {
            if (lat != null && lng != null)
            {
                Geocoder        gcd       = new Geocoder(mAct, Locale.Default);
                IList <Address> addresses = gcd.GetFromLocation((double)lat, (double)lng, 1);
                if (addresses.Count > 0)
                {
                    return(addresses[0].Locality);
                }
            }

            return(string.Empty);
        }
        public void OnLocationChanged(Android.Locations.Location location)
        {
            Log.Debug(tag, "Location changed");
            var            lat             = location.Latitude;
            var            lng             = location.Longitude;
            var            geo             = new Geocoder(this);
            List <Address> getAddress      = new List <Address>(geo.GetFromLocation(lat, lng, 1));
            Address        returnedAddress = getAddress.FirstOrDefault();

            if (returnedAddress != null)
            {
                System.Text.StringBuilder strReturnedAddress = new StringBuilder();
                for (int i = 0; i < returnedAddress.MaxAddressLineIndex; i++)
                {
                    strReturnedAddress.Append(returnedAddress.GetAddressLine(i)).AppendLine(" ");
                }
                loc.Text    = strReturnedAddress.ToString();
                getLoc.Text = "My Location";
                pos1        = new Xamarin.Forms.Labs.Services.Geolocation.Position()
                {
                    Latitude  = location.Latitude,
                    Longitude = location.Longitude
                };


                //determine whether closer to los gatos or palo alto
                if (loc.Text.Contains("Palo Alto"))
                {
                    town            = false;
                    getSpot.Enabled = true;
                }
                else if (loc.Text.Contains("Los Gatos"))
                {
                    town            = true;
                    getSpot.Enabled = true;
                }
                else
                {
                    //set alert for executing the task
                    AlertDialog.Builder alert = new AlertDialog.Builder(this);
                    alert.SetTitle("Sorry, you are too far from Palo Alto or Los Gatos");
                    alert.SetNeutralButton("OK", (senderAlert, args) => {});
                    //run the alert in UI thread to display in the screen
                    RunOnUiThread(() => {
                        alert.Show();
                    });
                }
            }
        }
Example #23
0
        public void OnLocationChanged(Location location)
        {
            try
            {
                _currentLocation = location;

                if (_currentLocation == null)
                {
                    Log.Debug("current location = ", "Unable to determine your location. Try again in a short while.");
                }
                else
                {
                    Log.Debug("current location = ", string.Format("{0:f6},{1:f6}", _currentLocation.Latitude, _currentLocation.Longitude));

                    Geocoder geocoder = new Geocoder(this);

                    //The Geocoder class retrieves a list of address from Google over the internet
                    IList <Address> addressList = geocoder.GetFromLocation(_currentLocation.Latitude, _currentLocation.Longitude, 10);

                    Address address = addressList.FirstOrDefault();

                    if (address != null)
                    {
                        StringBuilder deviceAddress = new StringBuilder();

                        for (int i = 0; i < address.MaxAddressLineIndex; i++)
                        {
                            deviceAddress.Append(address.GetAddressLine(i))
                            .AppendLine(",");
                        }

                        _strAddress = deviceAddress.ToString();

                        if (map != null)
                        {
                            display();
                        }
                    }
                    else
                    {
                        _strAddress = "Unable to determine the address.";
                    }
                }
            }
            catch
            {
                _strAddress = "Unable to determine the address.";
            }
        }
Example #24
0
        public void OnLocationChanged(Location location)
        {
            _latEditText.Text  = location.Latitude.ToString();
            _longEditText.Text = location.Longitude.ToString();

            var geocdr    = new Geocoder(this);
            var addresses = geocdr.GetFromLocation(location.Latitude, location.Longitude, 5);

            if (addresses.Any())
            {
                UpdateAddressFields(addresses.First());
            }

            _progressDialog.Cancel();
        }
        private Address ReverseGeocodeCurrentLocation(Location loc)
        {
            try
            {
                Geocoder        geocoder    = new Geocoder(ApplicationContext);
                IList <Address> addressList = geocoder.GetFromLocation(loc.Latitude, loc.Longitude, 10);

                Address address = addressList.FirstOrDefault();
                return(address);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Example #26
0
        public void OnLocationChanged(Android.Locations.Location location)
        {
            latitude.Text  = Resources.GetString(Resource.String.latitude_string, location.Latitude);
            longitude.Text = Resources.GetString(Resource.String.longitude_string, location.Longitude);
            provider.Text  = Resources.GetString(Resource.String.provider_string, location.Provider);
            lat            = location.Latitude;
            lon            = location.Longitude;
            //latitude.SetText(" "+location.Latitude);
            Geocoder        geo  = new Geocoder(this, Java.Util.Locale.English);
            IList <Address> addr = geo.GetFromLocation(lat, lon, 1);

            addr.ToList().ForEach((ad) => {
                place = ad.Locality;
            });
            SetUpMap();
        }
Example #27
0
        Address ReverseGeocodeCurrentLocation()
        {
            Geocoder geocoder = new Geocoder(this);
            Address  addr;

            try
            {
                IList <Address> addressList = geocoder.GetFromLocation(_currentLocation.Latitude, _currentLocation.Longitude, 1);
                addr = addressList.FirstOrDefault();
            }
            catch
            {
                addr = null;
            }
            return(addr);
        }
Example #28
0
        public void OnLocationChanged(Location location)
        {
            try
            {
                Address addressCurrent;
                if (location == null)
                {
                    return;
                }
                else
                {
                    //Start Timer and run for 5 seconds to detemine the optimal location.

                    if (IsBetterLocation(location, _currentLocation))
                    {
                        _currentLocation = location;

                        Geocoder geocoder = new Geocoder(this);

                        //The Geocoder class retrieves a list of address from Google over the internet
                        IList <Address> addressList = geocoder.GetFromLocation(location.Latitude, location.Longitude, 10);

                        addressCurrent = addressList.FirstOrDefault();
                        if (addressCurrent != null)
                        {
                            StringBuilder deviceAddress = new StringBuilder();

                            for (int i = 0; i < addressCurrent.MaxAddressLineIndex; i++)
                            {
                                deviceAddress.Append(addressCurrent.GetAddressLine(i))
                                .AppendLine(",");
                            }

                            _address = deviceAddress.ToString();
                        }
                        else
                        {
                            _address = "Unable to determine the address.";
                        }
                    }
                }
            }
            catch (Exception)
            {
                return;
            }
        }
Example #29
0
        public void OnLocationChanged(Location location)
        {
            try
            {
                currentLocation = location;

                if (currentLocation == null)
                {
                    locationText.Text = "Unable to determine your location.";
                }
                else
                {
                    locationText.Text   = String.Format("{0},{1}", currentLocation.Latitude, currentLocation.Longitude);
                    longtitudeText.Text = Convert.ToString(currentLocation.Longitude);
                    latitudeText.Text   = Convert.ToString(currentLocation.Latitude);

                    Geocoder geocoder = new Geocoder(this);

                    //The Geocoder class retrieves a list of address from Google over the internet
                    IList <Address> addressList = geocoder.GetFromLocation(currentLocation.Latitude, currentLocation.Longitude, 10);

                    Address address = addressList.FirstOrDefault();

                    if (address != null)
                    {
                        StringBuilder deviceAddress = new StringBuilder();

                        for (int i = 0; i < address.MaxAddressLineIndex; i++)
                        {
                            deviceAddress.Append(address.GetAddressLine(i))
                            .AppendLine(",");
                        }

                        addressText.Text = deviceAddress.ToString();
                    }
                    else
                    {
                        addressText.Text = "Unable to determine the address.";
                    }
                }
            }
            catch
            {
                addressText.Text = "Unable to determine the address.";
            }
        }
Example #30
0
        public void OnLocationChanged(Location location)
        {
            TextView locationText = FindViewById <TextView> (Resource.Id.locationTextView);

            locationText.Text = String.Format("Latitude = {0}, Longitude = {1}", location.Latitude, location.Longitude);

            Task.Factory.StartNew(() => {
                // Do the reverse geocoding on a background thread.
                Geocoder geocdr           = new Geocoder(this);
                IList <Address> addresses = geocdr.GetFromLocation(location.Latitude, location.Longitude, 5);
                return(addresses);
            })
            .ContinueWith(task => {
                TextView addrText = FindViewById <TextView> (Resource.Id.addressTextView);
                task.Result.ToList().ForEach((addr) => addrText.Append(addr.ToString() + "\r\n\r\n"));
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }