Example #1
0
        public async Task <(string PositionAddress, string PointName)> GetPositionAddress(Position position)
        {
            string          address          = string.Empty;
            string          pointName        = string.Empty;
            SyncPossibility possibility      = new SyncPossibility();
            bool            networkAvailable = await possibility.CheckAsync(false);

            if (networkAvailable)
            {
                var locator = CrossGeolocator.Current;
                try
                {
                    IEnumerable <Address> addresses = await locator.GetAddressesForPositionAsync(position);

                    var addressItem = addresses.FirstOrDefault();
                    if (addressItem != null)
                    {
                        address = $"{addressItem.SubThoroughfare}, {addressItem.Thoroughfare}, {addressItem.Locality}, {addressItem.CountryName}";
                        if (!string.IsNullOrEmpty(addressItem.SubLocality))
                        {
                            pointName = $"{addressItem.SubLocality}";
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(addressItem.Locality))
                            {
                                pointName = $"{addressItem.CountryName},{addressItem.Locality}";
                            }
                            else
                            {
                                pointName = $"{addressItem.CountryName},{addressItem.SubAdminArea}";
                            }
                        }
                    }
                }
                catch (Exception exception)
                {
                    var properties = new Dictionary <string, string> {
                        { "GeolocatorManager", "GetPositionAddress" }
                    };
                    Crashes.TrackError(exception, properties);
                }
            }
            return(address, pointName);
        }