Exemple #1
0
        public void GeocodeAddress(string address, string city, string state, string zipCode, string country)
        {
            if (locatorConfig.EnableLocator == ServiceSource.BING)
            {
                ESRI.ArcGIS.Client.Bing.Geocoder bingLocator = new ESRI.ArcGIS.Client.Bing.Geocoder(locatorConfig.BingLocator.Token, locatorConfig.BingLocator.ServerType);
                address = (string.IsNullOrEmpty(address)) ? "" : address + ",";
                city    = (string.IsNullOrEmpty(city)) ? "" : city + ",";
                string formatAddress = string.Format("{0} {1} {2} {3}", address, city, state, zipCode, country);
                if (!string.IsNullOrEmpty(country))
                {
                    formatAddress += "," + country;
                }
                bingLocator.Geocode(formatAddress, new EventHandler <ESRI.ArcGIS.Client.Bing.GeocodeService.GeocodeCompletedEventArgs>(BingLocator_GeocodeCompleted));
            }
            else if (locatorConfig.ArcGISLocator != null)
            {
                ESRI.ArcGIS.Client.Tasks.Locator locatorTask = new ESRI.ArcGIS.Client.Tasks.Locator(locatorConfig.ArcGISLocator.RESTURL);
                locatorTask.AddressToLocationsCompleted += new EventHandler <ESRI.ArcGIS.Client.Tasks.AddressToLocationsEventArgs>(ArcGISLocator_GeocodeCompleted);
                locatorTask.Failed += new EventHandler <TaskFailedEventArgs>(ArcGISLocatorTask_Failed);
                AddressToLocationsParameters addressParams = new AddressToLocationsParameters();
                ArcGISLocatorParams          paramFields   = locatorConfig.ArcGISLocator.ParameterFields;

                if (!string.IsNullOrEmpty(paramFields.AddressField))
                {
                    addressParams.Address.Add(paramFields.AddressField, address);
                }
                if (!string.IsNullOrEmpty(paramFields.CityField))
                {
                    addressParams.Address.Add(paramFields.CityField, city);
                }
                if (!string.IsNullOrEmpty(paramFields.StateField))
                {
                    addressParams.Address.Add(paramFields.StateField, state);
                }
                if (!string.IsNullOrEmpty(paramFields.ZipField))
                {
                    addressParams.Address.Add(paramFields.ZipField, zipCode);
                }
                if (!string.IsNullOrEmpty(paramFields.CountryField))
                {
                    addressParams.Address.Add(paramFields.CountryField, country);
                }

                locatorTask.AddressToLocationsAsync(addressParams);
            }
        }
Exemple #2
0
        /// <summary>
        /// Geocoding a single line address - using a locator service of ArcGIS Server above 10.0
        /// </summary>
        /// <param name="singleLineAddress">Single Line Address</param>
        public void GeocodeAddress(string singleLineAddress)
        {
            if (locatorConfig.EnableLocator == ServiceSource.BING)
            {
                ESRI.ArcGIS.Client.Bing.Geocoder bingLocator = new ESRI.ArcGIS.Client.Bing.Geocoder(locatorConfig.BingLocator.Token, locatorConfig.BingLocator.ServerType);
                bingLocator.Geocode(singleLineAddress, new EventHandler <ESRI.ArcGIS.Client.Bing.GeocodeService.GeocodeCompletedEventArgs>(BingLocator_GeocodeCompleted));
            }
            else if (locatorConfig.ArcGISLocator != null)
            {
                ESRI.ArcGIS.Client.Tasks.Locator locatorTask = new ESRI.ArcGIS.Client.Tasks.Locator(locatorConfig.ArcGISLocator.RESTURL);
                locatorTask.AddressToLocationsCompleted += new EventHandler <ESRI.ArcGIS.Client.Tasks.AddressToLocationsEventArgs>(ArcGISLocator_GeocodeCompleted);
                locatorTask.Failed += new EventHandler <TaskFailedEventArgs>(ArcGISLocatorTask_Failed);
                AddressToLocationsParameters addressParams = new AddressToLocationsParameters();
                addressParams.Address.Add("SingleLine", singleLineAddress);

                locatorTask.AddressToLocationsAsync(addressParams);
            }
        }