BikeInCity.ServiceCaller.ServiceCaller.GeocodeAddress C# (CSharp) Метод

GeocodeAddress() публичный Метод

Calls bing maps api to geocode address specified in string parametr.
public GeocodeAddress ( string address, EventHandler handler ) : void
address string
handler EventHandler
Результат void
        public void GeocodeAddress(string address, EventHandler<GeocodeCompletedEventArgs> handler)
        {
            //if no address was specified, ignore it
              if (address == null || address == String.Empty)
              {
            return;
              }

              GeocodeRequest geocodeRequest = new GeocodeRequest();

              // Set the credentials using a valid Bing Maps key
              geocodeRequest.Credentials = new Credentials();
              geocodeRequest.Credentials.ApplicationId = _applicationID;

              // Set the full address query
              geocodeRequest.Query = address;

              // Set the options to only return high confidence results
              ConfidenceFilter filter = new ConfidenceFilter();

              filter.MinimumConfidence = GeocodeService.Confidence.High;
              ObservableCollection<FilterBase> filtersCol = new ObservableCollection<FilterBase>();
              filtersCol.Add(filter);

              // Add the filters to the options
              GeocodeOptions geocodeOptions = new GeocodeOptions();
              geocodeOptions.Filters = filtersCol;
              geocodeRequest.Options = geocodeOptions;

              // Make the geocode request
              GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");

              geocodeService.GeocodeCompleted += handler;
              geocodeService.GeocodeAsync(geocodeRequest);
        }

Usage Example

Пример #1
0
        private void ComputeDirections_Click(object sender, RoutedEventArgs e)
        {
            //hide the directions panel
            DirectionsPanel.Visibility = System.Windows.Visibility.Collapsed;

            string address = String.Empty;

            //if the address does not contain the name of the city, we will add it
            if (!this.AddressTextBox.Text.Contains(CurrentCity.Name))
            {
                address = String.Format("{0},{1}", this.AddressTextBox.Text, CurrentCity.Name);
            }
            else
            {
                address = this.AddressTextBox.Text;
            }


            //call the geocode
            if (_currentState == BikeInCity.State.Directions)
            {
                _serviceCaller.GeocodeAddress(address, GeocodeForDirectionsCompleted);
            }
            else
            {
                _serviceCaller.GeocodeAddress(address, GeocodeForStationsCompleted);
            }
        }