Пример #1
0
        private List <LocationCandidate> ConvertBingGeocodeResults(GeocodeResponse response)
        {
            List <LocationCandidate> results = new List <LocationCandidate>();

            if (response != null && response.Results.Count > 0)
            {
                MapPoint          location  = null;
                LocationCandidate candidate = null;

                foreach (GeocodeResult result in response.Results)
                {
                    location  = new MapPoint(result.Locations[0].Longitude, result.Locations[0].Latitude, new SpatialReference(4326));
                    candidate = new LocationCandidate(100, result.DisplayName, location, locatorConfig.LocationSymbol.ImageSource);
                    results.Add(candidate);
                }
            }

            return(results);
        }
Пример #2
0
        private void ArcGISLocator_ReverseGeocodeCompleted(object sender, ESRI.ArcGIS.Client.Tasks.AddressEventArgs args)
        {
            List <LocationCandidate> results = new List <LocationCandidate>();

            if (args.Address != null)
            {
                string value         = "";
                string formatAddress = "";
                Dictionary <string, object> values = args.Address.Attributes;
                ArcGISLocatorParams         fields = locatorConfig.ArcGISLocator.ParameterFields;

                if (fields.AddressField != null && values.ContainsKey(fields.AddressField))
                {
                    value = (string)values[fields.AddressField];
                    if (!string.IsNullOrEmpty(value))
                    {
                        formatAddress += value.Trim() + ", ";
                    }
                }

                if (fields.CityField != null && values.ContainsKey(fields.CityField))
                {
                    value = (string)values[fields.CityField];
                    if (!string.IsNullOrEmpty(value))
                    {
                        formatAddress += value.Trim();
                    }
                }

                if (fields.StateField != null && values.ContainsKey(fields.StateField))
                {
                    value = (string)values[fields.StateField];
                    if (!string.IsNullOrEmpty(value))
                    {
                        formatAddress += ", " + value.Trim() + " ";
                    }
                }

                if (fields.ZipField != null && values.ContainsKey(fields.ZipField))
                {
                    value = (string)values[fields.ZipField];
                    if (!string.IsNullOrEmpty(value))
                    {
                        formatAddress += value.Trim();
                    }
                }

                if (fields.CountryField != null && values.ContainsKey(fields.CountryField))
                {
                    value = (string)values[fields.CountryField];
                    if (!string.IsNullOrEmpty(value))
                    {
                        formatAddress += ", " + value.Trim();
                    }
                }

                if (formatAddress == "")
                {
                    formatAddress = "Address is unavailable";
                }
                LocationCandidate candidate = new LocationCandidate(100, formatAddress, args.Address.Location, locatorConfig.LocationSymbol.ImageSource);
                results.Add(candidate);
            }

            if (results.Count > 0)
            {
                int srWKID = results[0].Location.SpatialReference.WKID;
                OnResultReady(results, srWKID, true); // With ArcGIS Server 10.01 later, reverse geocoding results have the same SR with the input point
            }
            else if (ResultReady != null)
            {
                ResultReady(this, new GeocodeResultEventArgs(results, true));
            }
        }