Ejemplo n.º 1
0
        static Task <IEnumerable <string> > GetAddressesForPositionAsync(Position position)
        {
            var location = new CLLocation(position.Latitude, position.Longitude);
            var geocoder = new CCLGeocoder();
            var source   = new TaskCompletionSource <IEnumerable <string> >();

            geocoder.ReverseGeocodeLocation(location, (placemarks, error) =>
            {
                if (placemarks == null)
                {
                    placemarks = new CLPlacemark[0];
                }
                List <string> addresses = new List <string>();
#if __MOBILE__
                addresses = placemarks.Select(p => ABAddressFormatting.ToString(p.AddressDictionary, false)).ToList();
#else
                foreach (var item in placemarks)
                {
                    var address        = new CNMutablePostalAddress();
                    address.Street     = item.AddressDictionary["Street"] == null ? "" : item.AddressDictionary["Street"].ToString();
                    address.State      = item.AddressDictionary["State"] == null ? "" : item.AddressDictionary["State"].ToString();
                    address.City       = item.AddressDictionary["City"] == null ? "" : item.AddressDictionary["City"].ToString();
                    address.Country    = item.AddressDictionary["Country"] == null ? "" : item.AddressDictionary["Country"].ToString();
                    address.PostalCode = item.AddressDictionary["ZIP"] == null ? "" : item.AddressDictionary["ZIP"].ToString();
                    addresses.Add(CNPostalAddressFormatter.GetStringFrom(address, CNPostalAddressFormatterStyle.MailingAddress));
                }
#endif
                source.SetResult(addresses);
            });
            return(source.Task);
        }
Ejemplo n.º 2
0
        static Task <IEnumerable <string> > GetAddressesForPositionAsync(Position position)
        {
            var location = new CLLocation(position.Latitude, position.Longitude);
            var geocoder = new CCLGeocoder();
            var source   = new TaskCompletionSource <IEnumerable <string> >();

            geocoder.ReverseGeocodeLocation(location, (placemarks, error) =>
            {
                if (placemarks == null)
                {
                    placemarks = new CLPlacemark[0];
                }
                List <string> addresses = new List <string>();
#if __MOBILE__ && !(MACCATALYST || MACOS || __MACCATALYST__)
#pragma warning disable BI1234, CA1416 // Type or member is obsolete, ABAddressFormatting.ToString(...) has [UnsupportedOSPlatform("ios9.0")]
                addresses = placemarks.Select(p => ABAddressFormatting.ToString(p.AddressDictionary, false)).ToList();
#pragma warning restore BI1234, CA1416 // Type or member is obsolete
#else
                foreach (var item in placemarks)
                {
                    var address = new CNMutablePostalAddress();
#pragma warning disable CA1416 // TODO: 'CLPlacemark.AddressDictionary' is unsupported on: 'maccatalyst' 11.0 and later
                    address.Street     = item.AddressDictionary["Street"] == null ? "" : item.AddressDictionary["Street"].ToString();
                    address.State      = item.AddressDictionary["State"] == null ? "" : item.AddressDictionary["State"].ToString();
                    address.City       = item.AddressDictionary["City"] == null ? "" : item.AddressDictionary["City"].ToString();
                    address.Country    = item.AddressDictionary["Country"] == null ? "" : item.AddressDictionary["Country"].ToString();
                    address.PostalCode = item.AddressDictionary["ZIP"] == null ? "" : item.AddressDictionary["ZIP"].ToString();
#pragma warning restore CA1416
                    addresses.Add(CNPostalAddressFormatter.GetStringFrom(address, CNPostalAddressFormatterStyle.MailingAddress));
                }
#endif
                source.SetResult(addresses);
            });
            return(source.Task);
        }
Ejemplo n.º 3
0
        void MapView_RegionChanged(object sender, MKMapViewChangeEventArgs e)
        {
            var mapView = (MKMapView)sender;

            _geocoder.ReverseGeocodeLocation(new CLLocation(mapView.CenterCoordinate.Latitude, mapView.CenterCoordinate.Longitude), (placemarks, error) =>
            {
                if (placemarks.Any())
                {
                    var address = ABAddressFormatting.ToString(placemarks[0].AddressDictionary, addCountryName: false);
                    _addressChanged.Invoke(address);
                }
            });
        }
        public void ChateauFrontenac()
        {
            using (NSMutableDictionary dict = new NSMutableDictionary()
            {
                { new NSString("Street"), new NSString("1–3 Rue Des Carrières") },
                { new NSString("SubAdministrativeArea"), new NSString("Québec") },
                { new NSString("Thoroughfare"), new NSString("Rue Des Carrières") },
                { new NSString("ZIP"), new NSString("G1R 5J5") },
                { new NSString("Name"), new NSString("1–3 Rue Des Carrières") },
                { new NSString("City"), new NSString("Quebec City") },
                { new NSString("State"), new NSString("Quebec") },
                { new NSString("SubLocality"), new NSString("Vieux-Quebec") },
                { new NSString("SubThoroughfare"), new NSString("1-3") },
                { new NSString("CountryCode"), new NSString("CA") },
            }) {
                string expected1 = "1–3 Rue Des Carrières\nQuebec City‎ Quebec‎ G1R 5J5";
                string expected2 = "1–3 Rue Des Carrières\nQuebec City Quebec G1R 5J5";                 // there's a "(char) 8206" character just after 'Quebec'
                string expected;
                string s = ABAddressFormatting.ToString(dict, false);
                if (TestRuntime.CheckXcodeVersion(9, 0))
                {
                    expected = expected2;
                }
                else
                {
                    expected = expected1;
                }
                Assert.That(s, Is.EqualTo(expected), "false");
                // country names can be translated, e.g. chinese, so we can't compare it
                s = ABAddressFormatting.ToString(dict, true);
                Assert.That(s, Does.StartWith(expected), "prefix");

                // Apple broke this again (8.0.x are hard to predict) - test will fail once it's corrected
                // iOS 8.1.2 device: working
                // iOS 8.0 (12A365) simulator (Xcode 6.0.1): working
                // iOS 8.1 (12B411) simulator (Xcode 6.1): broken
                // iOS 8.2 beta 5 (12D5480a) simulator (Xcode 6.2 beta 5): working

                // we don't check before 8.2 - where both device and simulators works again properly
                if (!TestRuntime.CheckSystemVersion(PlatformName.iOS, 8, 2))
                {
                    return;
                }

                // iOS 11.0 beta 1, 2, 3 and 4 are broken
                // and I give up (this test was not meant to track Apple breakages)
            }
        }
Ejemplo n.º 5
0
        static Task <IEnumerable <string> > GetAddressesForPositionAsync(Position position)
        {
            var location = new CLLocation(position.Latitude, position.Longitude);
            var geocoder = new CLGeocoder();
            var source   = new TaskCompletionSource <IEnumerable <string> >();

            geocoder.ReverseGeocodeLocation(location, (placemarks, error) =>
            {
                if (placemarks == null)
                {
                    placemarks = new CLPlacemark[0];
                }
                IEnumerable <string> addresses = placemarks.Select(p => ABAddressFormatting.ToString(p.AddressDictionary, false));
                source.SetResult(addresses);
            });
            return(source.Task);
        }
        public void ChateauFrontenac()
        {
            using (NSMutableDictionary dict = new NSMutableDictionary()
            {
                { new NSString("Street"), new NSString("1–3 Rue Des Carrières") },
                { new NSString("SubAdministrativeArea"), new NSString("Québec") },
                { new NSString("Thoroughfare"), new NSString("Rue Des Carrières") },
                { new NSString("ZIP"), new NSString("G1R 5J5") },
                { new NSString("Name"), new NSString("1–3 Rue Des Carrières") },
                { new NSString("City"), new NSString("Quebec City") },
                { new NSString("State"), new NSString("Quebec") },
                { new NSString("SubLocality"), new NSString("Vieux-Quebec") },
                { new NSString("SubThoroughfare"), new NSString("1-3") },
                { new NSString("CountryCode"), new NSString("CA") },
            }) {
                string expected = "1–3 Rue Des Carrières\nQuebec City‎ Quebec‎ G1R 5J5";
                string s        = ABAddressFormatting.ToString(dict, false);
                Assert.That(s, Is.EqualTo(expected), "false");
                // country names can be translated, e.g. chinese, so we can't compare it
                s = ABAddressFormatting.ToString(dict, true);
                Assert.True(s.StartsWith(expected, StringComparison.Ordinal), "prefix");

                // Apple broke this again (8.0.x are hard to predict) - test will fail once it's corrected
                // iOS 8.1.2 device: working
                // iOS 8.0 (12A365) simulator (Xcode 6.0.1): working
                // iOS 8.1 (12B411) simulator (Xcode 6.1): broken
                // iOS 8.2 beta 5 (12D5480a) simulator (Xcode 6.2 beta 5): working

                // we don't check before 8.2 - where both device and simulators works again properly
                if (!UIDevice.CurrentDevice.CheckSystemVersion(8, 2))
                {
                    return;
                }

                Assert.That(s [expected.Length], Is.EqualTo('\n'), "newline");
                Assert.That(s.Length > expected.Length + 1, "country");
            }
        }