Пример #1
0
        private void GeocodeAddress(string input)
        {
            using (GeocodeService.GeocodeServiceClient client = new GeocodeService.GeocodeServiceClient("CustomBinding_IGeocodeService"))
            {
                GeocodeService.GeocodeRequest request = new GeocodeService.GeocodeRequest();
                request.Credentials = new Credentials()
                {
                    ApplicationId = (App.Current.Resources["BingCredentials"] as ApplicationIdCredentialsProvider).ApplicationId
                };
                request.Query = Address;
                GeocodeResult = client.Geocode(request).Results[0];

                LocationAddress = GeocodeResult.Address.FormattedAddress;
                Latitude        = GeocodeResult.Locations[0].Latitude;
                Longitude       = GeocodeResult.Locations[0].Longitude;
                Location        = new Location(Latitude, Longitude);
                PinVisible      = Visibility.Visible;
            }
        }
    private void GeocodeAddress(string input)
    {
      using (GeocodeService.GeocodeServiceClient client = new GeocodeService.GeocodeServiceClient("CustomBinding_IGeocodeService"))
      {
        GeocodeService.GeocodeRequest request = new GeocodeService.GeocodeRequest();
        request.Credentials = new Credentials() { ApplicationId = (App.Current.Resources["BingCredentials"] as ApplicationIdCredentialsProvider).ApplicationId };
        request.Query = Address;
        GeocodeResult = client.Geocode(request).Results[0];

        LocationAddress = GeocodeResult.Address.FormattedAddress;
        Latitude = GeocodeResult.Locations[0].Latitude;
        Longitude = GeocodeResult.Locations[0].Longitude;
        Location = new Location(Latitude, Longitude);
        PinVisible = Visibility.Visible;
      }
    }
        /// <summary>
        /// Converts the address into GPS coordinates (latitude and longitude)
        /// </summary>
        /// <param name="address">The address to be converted.</param>
        /// <returns>"latitude, longitude"</returns>
        public string MakeGeocodeRequest(string address)
        {
            try
            {
                CultureInfo culture = CultureInfo.CreateSpecificCulture("en-US");
                // Set a Bing Maps key before making a request

                GeocodeService.GeocodeRequest geocodeRequest = new GeocodeService.GeocodeRequest();

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

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

                // Set the options to only return high confidence results
                GeocodeService.ConfidenceFilter[] filters = new GeocodeService.ConfidenceFilter[1];
                filters[0] = new GeocodeService.ConfidenceFilter();
                filters[0].MinimumConfidence = GeocodeService.Confidence.High;

                GeocodeService.GeocodeOptions geocodeOptions = new GeocodeService.GeocodeOptions();
                geocodeOptions.Filters = filters;

                geocodeRequest.Options = geocodeOptions;

                // Make the geocode request
                GeocodeService.GeocodeServiceClient geocodeService =
                new GeocodeService.GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
                GeocodeService.GeocodeResponse geocodeResponse = geocodeService.Geocode(geocodeRequest);

                if (geocodeResponse.Results.Count() == 0)
                {
                    return "No location found.";
                }
                return geocodeResponse.Results[0].Locations[0].Latitude.ToString(culture) + "," + geocodeResponse.Results[0].Locations[0].Longitude.ToString(culture);

            }
            catch (Exception)
            {
                return "An exception occurred.";
            }
        }