Exemplo n.º 1
0
 /// <summary>
 /// Reverse geocode - Find a point's address
 /// </summary>
 /// <param name="mapPoint">A point with its Spatial Reference matching the locator's Spatial Reference</param>
 /// <param name="searchDistance">Search distance around the point (ignored by BING locator)</param>
 public void ReverseGeocode(MapPoint mapPoint)
 {
     if (locatorConfig.EnableLocator == ServiceSource.BING)
     {
         ESRI.ArcGIS.Client.Bing.Geocoder BingLocator = new ESRI.ArcGIS.Client.Bing.Geocoder(locatorConfig.BingLocator.Token, locatorConfig.BingLocator.ServerType);
         BingLocator.ReverseGeocode(mapPoint, new EventHandler <ESRI.ArcGIS.Client.Bing.GeocodeService.ReverseGeocodeCompletedEventArgs>(BingLocator_ReverseGeocodeCompleted));
     }
     else if (locatorConfig.ArcGISLocator != null)
     {
         ESRI.ArcGIS.Client.Tasks.Locator locatorTask = new ESRI.ArcGIS.Client.Tasks.Locator(locatorConfig.ArcGISLocator.RESTURL);
         locatorTask.LocationToAddressCompleted += new EventHandler <ESRI.ArcGIS.Client.Tasks.AddressEventArgs>(ArcGISLocator_ReverseGeocodeCompleted);
         locatorTask.Failed += new EventHandler <TaskFailedEventArgs>(ArcGISLocatorTask_Failed);
         locatorTask.LocationToAddressAsync(mapPoint, locatorConfig.ArcGISLocator.SearchDistance);
     }
 }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
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);
            }
        }