/// <summary> /// Calls bing maps api to geocode address specified in string parametr. /// </summary> /// <param name="address"></param> /// <param name="handler"></param> 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); }
public string GeocodeAddress( string address ) { try { string results = ""; string key = "AplxUm9o3hkw6qCXBbp61H7HYlDrz-qz8ldgKLJ8Udjd8MFNJAfxxy2IWrfd4bw8"; GeocodeRequest geocodeRequest = new 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 ConfidenceFilter[] filters = new ConfidenceFilter[1]; filters[0] = new ConfidenceFilter(); filters[0].MinimumConfidence = GeocodeService.Confidence.Medium; // Add the filters to the options GeocodeOptions geocodeOptions = new GeocodeOptions(); geocodeOptions.Filters = filters; geocodeRequest.Options = geocodeOptions; // Make the geocode request GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService"); GeocodeResponse geocodeResponse = geocodeService.Geocode(geocodeRequest); if (geocodeResponse.Results.Length > 0) { Latitude = geocodeResponse.Results[0].Locations[0].Latitude; Longitude = geocodeResponse.Results[0].Locations[0].Longitude; results = String.Format("Latitude: {0}\nLongitude: {1}", Latitude, Longitude); } else { results = "No Results Found"; } return results; } catch (Exception ex) { return ex.Message; } }
void GeocodeAddress(string address) { var geocodeRequest = new GeocodeRequest { Credentials = new Credentials { ApplicationId = App.Self.APIKEY, }, Query = address, Address = new Address() }; var filters = new ConfidenceFilter[1]; filters[0] = new ConfidenceFilter(); filters[0].MinimumConfidence = Confidence.High; var geocodeOptions = new GeocodeOptions { Filters = filters }; geocodeRequest.Options = geocodeOptions; var geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService"); var myLoc = new Location(); geocodeService.GeocodeCompleted += async(object sender, GeocodeCompletedEventArgs e) => { if (e.Error == null) { var res = e.Result; if (e.Result.Results.Length > 0) { if (e.Result.Results[0].Locations.Length > 0) { myLoc = e.Result.Results[0].Locations[0]; var uri = await Map.GetMapUri(myLoc.Latitude, myLoc.Longitude, 2, "HYBRID", 300, 300); await Navigation.PushAsync(new Map(uri)); } } } }; geocodeService.GeocodeAsync(geocodeRequest); }
public static geoResponse geocodeAddress(string address) { geoResponse results = new geoResponse(); results.message = "No Results Found"; results.status = "fail"; if (!string.IsNullOrEmpty(address.Trim())) { // get key from configuration string key = "ApjKKP3xo-UePHYy4EWVj7kzRUAx40rbKSGGCzw-E_jK2YAtyhs5Na0_PunRgr2Y"; GeocodeRequest geocodeRequest = new GeocodeRequest(); // Set the credentials using a valid Bing Maps key geocodeRequest.Credentials = new bingMapGeocodeService.Credentials(); geocodeRequest.Credentials.ApplicationId = key; // Set the full address query geocodeRequest.Query = address; // Set the options to only return high confidence results ConfidenceFilter[] filters = new ConfidenceFilter[1]; filters[0] = new ConfidenceFilter(); filters[0].MinimumConfidence = bingMapGeocodeService.Confidence.High; // Add the filters to the options GeocodeOptions geocodeOptions = new GeocodeOptions(); geocodeOptions.Filters = filters; geocodeRequest.Options = geocodeOptions; // Make the geocode request GeocodeServiceClient geocodeService = new GeocodeServiceClient(); GeocodeResponse geocodeResponse = geocodeService.Geocode(geocodeRequest); if (geocodeResponse.Results.Length > 0) { results.latitude = geocodeResponse.Results[0].Locations[0].Latitude.ToString(); results.longitude = geocodeResponse.Results[0].Locations[0].Longitude.ToString(); results.status = "ok"; } } return results; }
public string GetLocation(string address) { //Set up some variables string results = ""; string key = "{Your Bing Key}"; try { //Create the geocode request, set the access key and the address to query GeocodeRequest geocodeRequest = new GeocodeRequest(); geocodeRequest.Credentials = new GeocodeService.Credentials(); geocodeRequest.Credentials.ApplicationId = key; geocodeRequest.Query = address; //Create a filter to return only high confidence results ConfidenceFilter[] filters = new ConfidenceFilter[1]; filters[0] = new ConfidenceFilter(); filters[0].MinimumConfidence = Confidence.High; //Apply the filter to the request GeocodeOptions options = new GeocodeOptions(); options.Filters = filters; geocodeRequest.Options = options; //Make the request GeocodeServiceClient client = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService"); GeocodeResponse response = client.Geocode(geocodeRequest); if (response.Results.Length > 0) { results = String.Format("Success: {0}:{1}", response.Results[0].Locations[0].Latitude, response.Results[0].Locations[0].Longitude); } else { results = "No Results Found"; } } catch (Exception e) { results = "Geocoding Error: " + e.Message; } return(results); }
public string GetLocation(string address) { string results = string.Empty; string key = "AsPcip7ChAzloBDBmSBoyyrjUgPL4PPigzM8-1rCIWLS5H5WGUJZyXZ971zqXACO"; try { //Create the geocode request, set the access key and the address to query GeocodeRequest geocodeRequest = new GeocodeRequest(); geocodeRequest.Credentials = new LocationChecker.GeocodeService.Credentials(); geocodeRequest.Credentials.ApplicationId = key; geocodeRequest.Query = address; //Create a filter to return only high confidence results ConfidenceFilter[] filters = new ConfidenceFilter[1]; filters[0] = new ConfidenceFilter(); filters[0].MinimumConfidence = Confidence.High; //Apply the filter to the request GeocodeOptions options = new GeocodeOptions(); //options.Filters = filters; geocodeRequest.Options = options; //Make the request GeocodeServiceClient client = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService"); GeocodeResponse response = client.Geocode(geocodeRequest); if (response.Results.Length > 0) { results = String.Format("Success:{0}:{1}:{2}", response.Results[0].Locations[0].Latitude, response.Results[0].Locations[0].Longitude, response.Results[0].Locations[0].Altitude); } else { results = "No Results Found"; } } catch (Exception e) { results = "Geocoding Error: " + e.Message; } return results; }
public Double[] GeocodeAddress(string address) { double[] re; GeocodeRequest geocodeRequest = new GeocodeRequest(); re = new double[2]; // Set the credentials using a valid Bing Maps key geocodeRequest.Credentials = new Microsoft.Maps.MapControl.WPF.Credentials(); geocodeRequest.Credentials.ApplicationId = key; // Set the full address query geocodeRequest.Query = address; // Set the options to only return high confidence results ConfidenceFilter[] filters = new ConfidenceFilter[1]; filters[0] = new ConfidenceFilter(); filters[0].MinimumConfidence = GeocodeService.Confidence.High; // Add the filters to the options GeocodeOptions geocodeOptions = new GeocodeOptions(); geocodeOptions.Filters = filters; geocodeRequest.Options = geocodeOptions; // Make the geocode request GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService"); GeocodeResponse geocodeResponse = geocodeService.Geocode(geocodeRequest); if (geocodeResponse.Results.Length > 0) { re[0] = geocodeResponse.Results[0].Locations[0].Latitude; re[1] = geocodeResponse.Results[0].Locations[0].Longitude; return(re); } else { re[0] = 0.0; re[1] = 0.0; return(re); } return(re); }
private String GeocodeAddress(string address) { string results = ""; string key = "ArLeGdHOcc5h7j3L4W37oFGcU9E-LF3tAZi4o0DfhXbPJ8aiyTGbIDNHex08R2u7"; GeocodeRequest geocodeRequest = new 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 ConfidenceFilter[] filters = new ConfidenceFilter[1]; filters[0] = new ConfidenceFilter(); filters[0].MinimumConfidence = GeocodeService.Confidence.High; // Add the filters to the options GeocodeOptions geocodeOptions = new GeocodeOptions(); geocodeOptions.Filters = filters; geocodeRequest.Options = geocodeOptions; // Make the geocode request GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService"); GeocodeResponse geocodeResponse = geocodeService.Geocode(geocodeRequest); if (geocodeResponse.Results.Length > 0) { results = String.Format("Latitude: {0}\nLongitude: {1}", geocodeResponse.Results[0].Locations[0].Latitude, geocodeResponse.Results[0].Locations[0].Longitude); } else { results = "No Results Found"; } return(results); }
//The Geocode Service private String GeocodeAddress(string address) { string results = ""; string key = "ApwndqJgdJ9M1Bpb7d_ihBwXW-J0N3HdXrZvFZqvFtmeYN5DewRoGPI7czgFo5Sh"; GeocodeRequest geocodeRequest = new 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 ConfidenceFilter[] filters = new ConfidenceFilter[1]; filters[0] = new ConfidenceFilter(); filters[0].MinimumConfidence = GeocodeService.Confidence.High; // Add the filters to the options GeocodeOptions geocodeOptions = new GeocodeOptions(); geocodeOptions.Filters = filters; geocodeRequest.Options = geocodeOptions; // Make the geocode request GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService"); GeocodeResponse geocodeResponse = geocodeService.Geocode(geocodeRequest); if (geocodeResponse.Results.Length > 0) { results = String.Format("Latitude: {0}\nLongitude: {1}", geocodeResponse.Results[0].Locations[0].Latitude, geocodeResponse.Results[0].Locations[0].Longitude); } else { results = "No Results Found"; } return(results); }
//Find the location by address private void GeocodeAddress(string address) { string results = ""; string key = "AnYws_sa62sPmXR-zcq6XDp8P9Sbtvbv3Bi3FtXkKc4jvOjmNwD3SeaHz54pAxpg"; GeocodeRequest geocodeRequest = new GeocodeRequest(); // Set the credentials using a valid Bing Maps key geocodeRequest.Credentials = new Microsoft.Maps.MapControl.WPF.Credentials(); geocodeRequest.Credentials.ApplicationId = key; // Set the full address query geocodeRequest.Query = address; // Set the options to only return high confidence results ConfidenceFilter[] filters = new ConfidenceFilter[1]; filters[0] = new ConfidenceFilter(); filters[0].MinimumConfidence = GeocodeService.Confidence.High; // Add the filters to the options GeocodeOptions geocodeOptions = new GeocodeOptions(); geocodeOptions.Filters = filters; geocodeRequest.Options = geocodeOptions; // Make the geocode request GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService"); GeocodeResponse geocodeResponse = geocodeService.Geocode(geocodeRequest); if (geocodeResponse.Results.Length > 0) { results = String.Format("Latitude: {0}\nLongitude: {1}", geocodeResponse.Results[0].Locations[0].Latitude, geocodeResponse.Results[0].Locations[0].Longitude); PlacePin(geocodeResponse.Results[0].Locations[0].Latitude, geocodeResponse.Results[0].Locations[0].Longitude); } else { results = "No Results Found"; } }
/// <summary> /// Calls bing maps api to geocode address specified in string parametr. /// </summary> /// <param name="address"></param> /// <param name="handler"></param> 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); }
private void button1_Click(object sender, EventArgs e) { CommonService tokenService = new CommonService(); tokenService.Credentials = new System.Net.NetworkCredential("137871", "Mugga25."); TokenSpecification tokenSpecs = new TokenSpecification(); tokenSpecs.ClientIPAddress = "0.0.0.0 "; tokenSpecs.TokenValidityDurationMinutes = 60; string token = tokenService.GetClientToken(tokenSpecs); textBox1.AppendText(token + Environment.NewLine); GeocodeRequest request = new GeocodeRequest(); request.Credentials = new Credentials(); request.Credentials.Token = token; request.Query = "1234"; GeocodeOptions options = new GeocodeOptions(); ConfidenceFilter[] filters = new ConfidenceFilter[] { new ConfidenceFilter() { MinimumConfidence = Confidence.Low } }; options.Filters = filters; request.Options = options; GeocodeServiceClient geoCoder = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService"); GeocodeResponse response = geoCoder.Geocode(request); foreach (var result in response.Results) { textBox1.AppendText("Display Name: " + result.DisplayName + Environment.NewLine); textBox1.AppendText("Confidence: " + result.Confidence.ToString() + Environment.NewLine); textBox1.AppendText("Entity Type: " + result.EntityType + Environment.NewLine); foreach (var location in result.Locations) { textBox1.AppendText("Longitude: " + location.Longitude + Environment.NewLine); textBox1.AppendText("Latitude: " + location.Latitude + Environment.NewLine); textBox1.AppendText("Altitude: " + location.Altitude + Environment.NewLine); } } //LiveMapsTokenService.CommonServiceSoapClient tokenService = new LiveMapsTest.LiveMapsTokenService.CommonServiceSoapClient("CommonServiceSoap"); //GetClientTokenRequest tokenRequest = new GetClientTokenRequest(); //tokenService.ClientCredentials.UserName.UserName = "******"; //tokenService.ClientCredentials.UserName.Password = "******"; }
public geoloc GeocodeAddress(string address) { GeocodeRequest geocodeRequest = new GeocodeRequest(); // Set the credentials using a valid Bing Maps key geocodeRequest.Credentials = new GeoCodeService.Credentials(); geocodeRequest.Credentials.ApplicationId = "AiIo0eq8yDzQx40gwHidcSJzTIZjanj36I5v_xVhbNCuB-3GTeJ0tkTM2c7exntM"; // Set the full address query geocodeRequest.Query = address; // Set the options to only return high confidence results ConfidenceFilter[] filters = new ConfidenceFilter[1]; filters[0] = new ConfidenceFilter(); filters[0].MinimumConfidence = GeoCodeService.Confidence.Low; // Add the filters to the options GeocodeOptions geocodeOptions = new GeocodeOptions(); geocodeOptions.Filters = filters; geocodeRequest.Options = geocodeOptions; // Make the geocode request GeoCodeService.GeocodeServiceClient geocodeService = new GeoCodeService.GeocodeServiceClient("BasicHttpBinding_IGeocodeService"); GeocodeResponse geocodeResponse = geocodeService.Geocode(geocodeRequest); if (geocodeResponse.Results.Length > 0) { geoloc res = new geoloc(); res.lat = geocodeResponse.Results[0].Locations[0].Latitude; res.lon = geocodeResponse.Results[0].Locations[0].Longitude; return res; } else throw new Exception("No Results Found"); }
private GeocodeResponse GeoCodeData(string address) { try { GeocodeRequest request = new GeocodeRequest(); request.Credentials = new GeocodeService.Credentials(); request.Credentials.ApplicationId = getConfig("BingApiKey"); request.Query = address; ConfidenceFilter[] filters = new ConfidenceFilter[1]; filters[0] = new ConfidenceFilter(); filters[0].MinimumConfidence = GeocodeService.Confidence.High; GeocodeOptions geocodeOptions = new GeocodeOptions(); geocodeOptions.Filters = filters; request.Options = geocodeOptions; GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService"); GeocodeResponse response = geocodeService.Geocode(request); if (response.Results.Length > 0) { return(response); } } catch { } return(null); }
private void GeocodeAddress(string address, RoutingState state) { GeocodeRequest request = new GeocodeRequest(); request.Query = address; // Don't raise exceptions. request.ExecutionOptions = new GeocodeService.ExecutionOptions(); request.ExecutionOptions.SuppressFaults = true; // Only accept results with high confidence. request.Options = new GeocodeService.GeocodeOptions(); // Using ObservableCollection since this is the default for Silverlight proxy generation. request.Options.Filters = new ObservableCollection<FilterBase>(); ConfidenceFilter filter = new ConfidenceFilter(); filter.MinimumConfidence = GeocodeService.Confidence.High; request.Options.Filters.Add(filter); if (null != state.output) { state.output.Text = "<geocoding in progress>"; state.output.Foreground = new SolidColorBrush(Colors.Black); } //it's in the resources already ((ClientTokenCredentialsProvider)App.Current.Resources["MyCredentials"]).GetCredentials( (Credentials credentials) => { // Pass in credentials for web services call. //Replace with your own Credentials. request.Credentials = credentials; // Make asynchronous call to fetch the data ... pass state object. GeocodeClient.GeocodeAsync(request, state); }); }
/// <summary> /// Locates an Address and Provides the Address details for Map Repositioning /// </summary> /// <param name="address">User Provided Address details</param> /// <param name="culture">the current culture of the map</param> /// <param name="credentials">Your Bing API Credentials</param> /// /// <remarks>Retrieve Data by creating an Event Handler for LocateAddressCompleted</remarks> public void LocateAddress(string address, string culture, Credentials credentials) { GeocodeRequest request = new GeocodeRequest(); request.Culture = culture; request.Query = address; // Don't raise exceptions. request.ExecutionOptions = new GeocodeService.ExecutionOptions(); request.ExecutionOptions.SuppressFaults = true; // Only accept results with high confidence. request.Options = new GeocodeOptions(); request.Options.Filters = new ObservableCollection<FilterBase>(); ConfidenceFilter filter = new ConfidenceFilter(); filter.MinimumConfidence = GeocodeService.Confidence.High; request.Options.Filters.Add(filter); //Pass in credentials for web services call. request.Credentials = credentials; // Make asynchronous call to fetch the data GeocodeClient.GeocodeAsync(request, address); }
private GeocodeService.Location GeocodeAddressGetLocation(string address) { string key = "l4o5yybDpLNG7xrsTmoP~A0DSZhcYTwcaKvEUgBi44g~AsAjqiCU7gZND03eLCfpdqNDGFXfMdzqXYLFVEGnFy1SgQSlDA8ld0BpbCgI4JsD"; GeocodeRequest geocodeRequest = new 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 ConfidenceFilter[] filters = new ConfidenceFilter[1]; filters[0] = new ConfidenceFilter(); filters[0].MinimumConfidence = GeocodeService.Confidence.High; // Add the filters to the options GeocodeOptions geocodeOptions = new GeocodeOptions(); geocodeOptions.Filters = filters; geocodeRequest.Options = geocodeOptions; // Make the geocode request GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService"); GeocodeResponse geocodeResponse; try { geocodeResponse = geocodeService.Geocode(geocodeRequest); } catch { MapLabelTextBox.Text = "Adresse non trouvée"; return null; } if (geocodeResponse.Results.Length > 0) { latitude = geocodeResponse.Results[0].Locations[0].Latitude.ToString(); longitude = geocodeResponse.Results[0].Locations[0].Longitude.ToString(); MapLabelTextBox.Text = address; return geocodeResponse.Results[0].Locations[0]; } else { MapLabelTextBox.Text = "Adresse non trouvée"; latitude = null; longitude = null; return null; } }
private LatLonPair DoBingGeocoding(string query) { try { var mappingCredentials = _settingsManager.GetString(Common.Constants.MappingApplicationId, Common.Constants.BingMapsKey); var geocodeRequest = new MEDSEEK.eHealth.Utils.Business.GeoCodeService.GeocodeRequest(); geocodeRequest.Credentials = new MEDSEEK.eHealth.Utils.Business.GeoCodeService.Credentials(); geocodeRequest.Credentials.ApplicationId = mappingCredentials; geocodeRequest.Query = query; // Set the options to only return high confidence results ConfidenceFilter[] filters = new ConfidenceFilter[1]; filters[0] = new ConfidenceFilter(); filters[0].MinimumConfidence = MEDSEEK.eHealth.Utils.Business.GeoCodeService.Confidence.High; // Add the filters to the options GeocodeOptions geocodeOptions = new GeocodeOptions(); geocodeOptions.Filters = filters; geocodeRequest.Options = geocodeOptions; // Make the geocode request GeocodeResponse geocodeResponse; using (var geocodeService = new GeocodeServiceClient()) { geocodeResponse = geocodeService.Geocode(geocodeRequest); } if (geocodeResponse.Results.Length > 0) { return new LatLonPair() { Latitude = geocodeResponse.Results[0].Locations[0].Latitude.ToString(CultureInfo.InvariantCulture), Longitude = geocodeResponse.Results[0].Locations[0].Longitude.ToString(CultureInfo.InvariantCulture) }; } } catch (Exception ex) { var exception = ex.InnerException != null ? ex.InnerException : ex; _logger.Error(ex.Message, exception); } return null; }
private String GeocodeAddress(string address) { string results = ""; string key = "ArLeGdHOcc5h7j3L4W37oFGcU9E-LF3tAZi4o0DfhXbPJ8aiyTGbIDNHex08R2u7"; GeocodeRequest geocodeRequest = new 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 ConfidenceFilter[] filters = new ConfidenceFilter[1]; filters[0] = new ConfidenceFilter(); filters[0].MinimumConfidence = GeocodeService.Confidence.High; // Add the filters to the options GeocodeOptions geocodeOptions = new GeocodeOptions(); geocodeOptions.Filters = filters; geocodeRequest.Options = geocodeOptions; // Make the geocode request GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService"); GeocodeResponse geocodeResponse = geocodeService.Geocode(geocodeRequest); if (geocodeResponse.Results.Length > 0) results = String.Format("Latitude: {0}\nLongitude: {1}", geocodeResponse.Results[0].Locations[0].Latitude, geocodeResponse.Results[0].Locations[0].Longitude); else results = "No Results Found"; return results; }
public String GeocodeAddress(string address) { string results = ""; GeocodeRequest geocodeRequest = new 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 ConfidenceFilter[] filters = new ConfidenceFilter[1]; filters[0] = new ConfidenceFilter(); filters[0].MinimumConfidence = GeocodeService.Confidence.High; // Add the filters to the options GeocodeOptions geocodeOptions = new GeocodeOptions(); geocodeOptions.Filters = filters; geocodeRequest.Options = geocodeOptions; // Make the geocode request GeocodeServiceClient geocodeService = new GeocodeServiceClient(); GeocodeResponse geocodeResponse = geocodeService.Geocode(geocodeRequest); if (geocodeResponse.Results.Length > 0) results = String.Format("Latitude: {0}\nLongitude: {1}", geocodeResponse.Results[0].Locations[0].Latitude, geocodeResponse.Results[0].Locations[0].Longitude); else results = "No Results Found"; return results; }
private void StartSearch(string address) { GeocodeRequest geocodeRequest = new GeocodeRequest(); // Set the credentials using a valid Bing Maps key geocodeRequest.Credentials = new Credentials(); geocodeRequest.Credentials.ApplicationId = m_BingKey; // Set the full address query geocodeRequest.Query = address; // Set the options to only return high confidence results ConfidenceFilter[] filters = new ConfidenceFilter[1]; filters[0] = new ConfidenceFilter(); filters[0].MinimumConfidence = GeocodeService.Confidence.High; // Add the filters to the options GeocodeOptions geocodeOptions = new GeocodeOptions(); geocodeOptions.Filters = filters; geocodeRequest.Options = geocodeOptions; ServicePointManager.UseNagleAlgorithm = true; // Switch off 100 continue expectation ServicePointManager.Expect100Continue = false; ServicePointManager.CheckCertificateRevocationList = true; ServicePointManager.DefaultConnectionLimit = ServicePointManager.DefaultPersistentConnectionLimit; // Make the geocode request m_SearchResults.Clear(); try { GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService"); GeocodeResponse geocodeResponse = geocodeService.Geocode(geocodeRequest); foreach (GeocodeService.GeocodeResult r in geocodeResponse.Results) { m_SearchResults.Add(r); lwResults.SelectedIndex = 0; btnSendCoords.IsEnabled = (m_SearchResults.Count > 0); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void TestSearch() { GeocodeRequest geocodeRequest = new GeocodeRequest(); // Set the credentials using a valid Bing Maps key //geocodeRequest.Credentials = new NErgy.Silverlight.GeocodeService.Credentials(); geocodeRequest.Credentials.ApplicationId = "AliveLsVdOVnhqNkgV_FToj2KurkqQev_CRld2F-3TRGJMzq5q8ycnNR9REGotXB"; // Set the full address query geocodeRequest.Query = address.Text ; ConfidenceFilter[] filters = new ConfidenceFilter[1]; filters[0] = new ConfidenceFilter(); filters[0].MinimumConfidence = GeocodeService.Confidence.High; GeocodeOptions geocodeOptions = new GeocodeOptions(); geocodeOptions.Filters = new System.Collections.ObjectModel.ObservableCollection<FilterBase>(filters); geocodeRequest.Options = geocodeOptions; GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService"); geocodeService.GeocodeCompleted += new EventHandler<GeocodeCompletedEventArgs>(geocodeService_GeocodeCompleted); geocodeService.GeocodeAsync(geocodeRequest); }