/// <summary> /// Makes the reverse geocode request. /// </summary> /// <param name="l">The l.</param> private void MakeReverseGeocodeRequest(Location l) { try { // Set a Bing Maps key before making a request const string KEY = "AkRhgqPR6aujo-xib-KiR8Lt20wsn89GY4R9SP0RA6h4w7QT9mS3kKwYKKxjklfV"; // Set the credentials using a valid Bing Maps key // Set the point to use to find a matching address var reverseGeocodeRequest = new ReverseGeocodeRequest { Credentials = new Credentials { ApplicationId = KEY } }; Location point = l; reverseGeocodeRequest.Location = point; reverseGeocodeRequest.UserProfile = new UserProfile { DeviceType = DeviceType.Mobile }; // Make the reverse geocode request var geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService"); geocodeService.ReverseGeocodeCompleted += lookupAddress_ReverseGeocodeCompleted; geocodeService.ReverseGeocodeAsync(reverseGeocodeRequest); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// /// </summary> /// <param name="point"></param> /// <returns></returns> private async Task <string> ReverseGeocodePoint(Location point) { ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest(); // Set the credentials using a valid Bing Maps key reverseGeocodeRequest.Credentials = new GeocodeService.Credentials(); reverseGeocodeRequest.Credentials.ApplicationId = Ressources.BingMapkey; // Set the point to use to find a matching address reverseGeocodeRequest.Location = point; reverseGeocodeRequest.Culture = "fr-FR"; // Make the reverse geocode request GeocodeServiceClient geocodeService = new GeocodeServiceClient(GeocodeServiceClient.EndpointConfiguration.BasicHttpBinding_IGeocodeService); GeocodeService.GeocodeResponse geocodeResponse = await geocodeService.ReverseGeocodeAsync(reverseGeocodeRequest); string Results = geocodeResponse.Results[0].DisplayName;//*/ return(Results); }
public static void ReverseGeocodeAddress(Dispatcher uiDispatcher, CredentialsProvider credentialsProvider, Location location, Action <GeocodeResult> completed = null, Action <GeocodeError> error = null) { completed = completed ?? (r => { }); error = error ?? (e => { }); // Get credentials and only then place an async call on the geocode service. credentialsProvider.GetCredentials(credentials => { var request = new ReverseGeocodeRequest() { // Pass in credentials for web services call. Credentials = credentials, Culture = CultureInfo.CurrentUICulture.Name, Location = location, // Don't raise exceptions. ExecutionOptions = new ExecutionOptions { SuppressFaults = true }, }; EventHandler <ReverseGeocodeCompletedEventArgs> reverseGeocodeCompleted = (s, e) => { try { if (e.Result.ResponseSummary.StatusCode != Bing.Geocode.ResponseStatusCode.Success || e.Result.Results.Count == 0) { // Report geocode error. uiDispatcher.BeginInvoke(() => error(new GeocodeError(e))); } else { // Only report on first result. var firstResult = e.Result.Results.First(); uiDispatcher.BeginInvoke(() => completed(firstResult)); } } catch (Exception ex) { uiDispatcher.BeginInvoke(() => error(new GeocodeError(ex.Message, ex))); } }; var geocodeClient = new GeocodeServiceClient(); geocodeClient.ReverseGeocodeCompleted += reverseGeocodeCompleted; geocodeClient.ReverseGeocodeAsync(request); }); }
async public Task <String> ReverseGeocodePoint(Bing.Maps.Location l) { //return await ReverseGeocodeGoogle(l.Longitude, l.Latitude); string key = "AqzQTQg1GrHIoL2a5Ycf08czzcxAooMpXiADdOgZQYPBtwpuSSf8Fd4y7MUTJo-h"; ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest(); // Set the credentials using a valid Bing Maps key reverseGeocodeRequest.Credentials = new geocodeservice.Credentials(); reverseGeocodeRequest.Credentials.ApplicationId = key; // Set the point to use to find a matching address geocodeservice.Location point = new geocodeservice.Location(); point.Latitude = l.Latitude; point.Longitude = l.Longitude; reverseGeocodeRequest.Location = point; // Make the reverse geocode request GeocodeServiceClient geocodeService = new GeocodeServiceClient(geocodeservice.GeocodeServiceClient.EndpointConfiguration.BasicHttpBinding_IGeocodeService); // sometimes reverseGeocode is not getting me the right location so we will try to call the service a couple of times until it works, after a bit of tryouts we just return an error. int numberOfTries = 10; GeocodeResponse geocodeResponse = await geocodeService.ReverseGeocodeAsync(reverseGeocodeRequest); while (geocodeResponse.Results.Count == 0) { geocodeResponse = await geocodeService.ReverseGeocodeAsync(reverseGeocodeRequest); if (numberOfTries == 0) { break; } numberOfTries--; } return(geocodeResponse.Results[0].Address.Locality); }
private void map_MouseClick(object sender, Microsoft.Maps.MapControl.MapMouseEventArgs e) { // 调用Bing Maps Geocode服务获得最近的位置. ReverseGeocodeRequest request = new ReverseGeocodeRequest() { Location = map.ViewportPointToLocation(e.ViewportPoint) }; request.Credentials = new Credentials() { Token = this._mapCredential }; _geocodeClient.ReverseGeocodeAsync(request); }
private void map_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { // Check to see if the finger has moved. Point clickedPoint = e.GetPosition(this.map); if (Math.Abs(clickedPoint.X - this.clickedPoint.X) < 5 && Math.Abs(clickedPoint.Y - this.clickedPoint.Y) < 5) { // Invoke Bing Maps Geocode service to obtain the nearest location. ReverseGeocodeRequest request = new ReverseGeocodeRequest() { Location = map.ViewportPointToLocation(e.GetPosition(this.map)) }; request.Credentials = new Credentials() { ApplicationId = this._mapCredential }; _geocodeClient.ReverseGeocodeAsync(request); } }
private void map_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { // 检查手指是否移动. Point clickedPoint = e.GetPosition(this.map); if (Math.Abs(clickedPoint.X - this.clickedPoint.X) < 5 && Math.Abs(clickedPoint.Y - this.clickedPoint.Y) < 5) { // 调用Bing Maps Geocode服务获得最近的位置. ReverseGeocodeRequest request = new ReverseGeocodeRequest() { Location = map.ViewportPointToLocation(e.GetPosition(this.map)) }; request.Credentials = new Credentials() { ApplicationId = this._mapCredential }; _geocodeClient.ReverseGeocodeAsync(request); } }
public void Find(Point location, EventHandler onResults) { if (IsInitialized) { var reverseGeocodeRequest = new ReverseGeocodeRequest { Credentials = new Credentials {Token = token}, Location = new Location {Longitude = location.X, Latitude = location.Y} }; var geocodeService = new GeocodeServiceClient(); geocodeService.ReverseGeocodeCompleted += (o, e) => { GeocodeResponse geocodeResponse = e.Result; onResults(this, new GeocodeResultArgs {Results = geocodeResponse.Results}); }; geocodeService.ReverseGeocodeAsync(reverseGeocodeRequest); } }
private void geocode_Click(object sender, EventArgs e) { GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService"); geocodeService.ReverseGeocodeCompleted += geocodeService_ReverseGeocodeCompleted; ReverseGeocodeRequest geocodeRequest = new ReverseGeocodeRequest() { Credentials = new Credentials { ApplicationId = "enter your developer key here" }, Location = new GeocodeLocation { Latitude = previous.Latitude, Longitude = previous.Longitude, } }; geocodeService.ReverseGeocodeAsync(geocodeRequest); }
/// <summary> /// This method will reverse geocode the ground station based on its location and /// call the callback method. /// </summary> /// <param name="name">Name of the ground station</param> /// <param name="id">id of the station</param> /// <param name="location">Location of the ground station</param> private void reverseGeocode(string name, string id, Location location) { ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest(); // Set the credentials using a valid Bing Maps key reverseGeocodeRequest.Credentials = new Credentials(); reverseGeocodeRequest.Credentials.ApplicationId = this.BingMapsKey; // Set the point to use to find a matching address GeocodeService.GeocodeLocation point = new GeocodeService.GeocodeLocation(); point.Latitude = location.Latitude; point.Longitude = location.Longitude; reverseGeocodeRequest.Location = point; // Make the reverse geocode request GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService"); geocodeService.ReverseGeocodeCompleted += new EventHandler <ReverseGeocodeCompletedEventArgs>( delegate(object sender, ReverseGeocodeCompletedEventArgs e) { this.reverseGeocodeCompleted(sender, e, name, id, location); }); geocodeService.ReverseGeocodeAsync(reverseGeocodeRequest); }
private void reverseGeocode(GeoCoordinate location) { ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest(); reverseGeocodeRequest.Credentials = new Credentials(); string AppId = App.Current.Resources["BingApplicationId"] as string; reverseGeocodeRequest.Credentials.ApplicationId = AppId; reverseGeocodeRequest.Location = location; GeocodeServiceClient geocodeClient = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService"); geocodeClient.ReverseGeocodeCompleted += geocodeClient_ReverseGeocodeCompleted; geocodeClient.ReverseGeocodeAsync(reverseGeocodeRequest); }
async void start_Tapped(object sender, TappedRoutedEventArgs e) { var point = e.GetPosition(myMap); var temAdrress = ""; Bing.Maps.Location loc; myMap.TryPixelToLocation(point, out loc); // Declare ReverseGeocode Request – This is the service that will return address for a particular point. ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest(); // Set the credentials using a valid Bing Maps key – Replace the text in green with your credentials reverseGeocodeRequest.Credentials = new GeocodeService.Credentials(); reverseGeocodeRequest.Credentials.ApplicationId = "IVMrdHQvM4jM61vTKgKj~TXSvY7rIpcx2F_BN8ng4SQ~AjX0mRb5gJOYJwB5sPCX2QD4t5bgLR9gHGxJvWGNV93rTgrYThbJM3N1w73r8v3u"; // Set the point to use to find a matching address GeocodeService.Location point1 = new GeocodeService.Location(); point1.Latitude = loc.Latitude; point1.Longitude = loc.Longitude; reverseGeocodeRequest.Location = point1; // Make the reverse geocode request GeocodeServiceClient geocodeService = new GeocodeServiceClient(GeocodeServiceClient.EndpointConfiguration.BasicHttpBinding_IGeocodeService); var geocodeResponse = await geocodeService.ReverseGeocodeAsync(reverseGeocodeRequest); if (geocodeResponse.Results.Count > 0) { temAdrress = geocodeResponse.Results[0].DisplayName; pop_search.IsOpen = true; txtBlk_popup.Text = "أنا" + "\n" + temAdrress; } }
public WeatherPage() { InitializeComponent(); client = new WeatherServiceClient( GetBinding(), GetEndpointAddress("Weather")); client.GetMyWeatherLocationsDetailsCompleted += (o1, e1) => { HideProgress(); LoadingMessage.Visibility = Visibility.Collapsed; if (e1.Error != null) { if (e1.Error.GetType() == typeof(FaultException <AuthenticationFault>)) { GetAuthenticationToken( new Action( () => { client.GetMyWeatherLocationsDetailsAsync(Settings.CachedAuthenticationToken); } )); } else { MessageBox.Show(e1.Error.Message); } return; } BitmapImage bi = null; weatherViewModel.Clear(); foreach (var w in e1.Result) { ObservableCollection <Weather> forecast = new ObservableCollection <Weather>(); if (w.Forecast != null) { foreach (var f in w.Forecast) { bi = new BitmapImage(); bi.SetSource(new MemoryStream(f.Icon)); forecast.Add( new Weather() { Condition = f.Condition, Date = f.Date.DayOfWeek.ToString(), Forecast = null, HighTemperature = String.Format(CultureInfo.InvariantCulture, "High: {0}", f.HighTemperature), Image = bi, Location = null, LowTemperature = String.Format(CultureInfo.InvariantCulture, "Low: {0}", f.LowTemperature), Temperature = null, }); } } bi = new BitmapImage(); bi.SetSource(new MemoryStream(w.Icon)); weatherViewModel.Add( new Weather() { Condition = w.Condition, Date = null, Forecast = forecast, HighTemperature = null, Image = bi, Location = w.Location, LowTemperature = null, Temperature = w.Temperature, }); } }; // this is used for the gps function client.GetWeatherCompleted += (o1, e1) => { if (e1.Error != null) { // TODO: return; } BitmapImage bi = null; if (weatherViewModel.FirstOrDefault(w => w.Location == e1.Result.Location) == null) { ObservableCollection <Weather> forecast = new ObservableCollection <Weather>(); if (e1.Result.Forecast != null) { foreach (var f in e1.Result.Forecast) { bi = new BitmapImage(); bi.SetSource(new MemoryStream(f.Icon)); forecast.Add( new Weather() { Condition = f.Condition, Date = f.Date.DayOfWeek.ToString(), Forecast = null, HighTemperature = String.Format(CultureInfo.InvariantCulture, "High: {0}", f.HighTemperature), Image = bi, Location = null, LowTemperature = String.Format(CultureInfo.InvariantCulture, "Low: {0}", f.LowTemperature), Temperature = null, }); } } bi = new BitmapImage(); bi.SetSource(new MemoryStream(e1.Result.Icon)); weatherViewModel.Add( new Weather() { Condition = String.Format(CultureInfo.InvariantCulture, "{0} degrees and {1}", e1.Result.Temperature, e1.Result.Condition), Date = null, Forecast = forecast, HighTemperature = null, Image = bi, Location = e1.Result.Location, LowTemperature = null, Temperature = null, }); } WeatherList.SelectedIndex = WeatherList.Items.IndexOf(WeatherList.Items.FirstOrDefault(w => (w as Weather).Location == e1.Result.Location)); HideProgress(); }; client.AddWeatherLocationCompleted += (o1, e1) => { if (e1.Error != null) { if (e1.Error.GetType() == typeof(FaultException <AuthenticationFault>)) { // TODO: //GetAuthenticationToken( // new Action( // () => // { // client.GetMyStockDataAsync(Settings.CachedAuthenticationToken); // } // )); } else { MessageBox.Show(e1.Error.Message); } HideProgress(); return; } if (!e1.Result) { MessageBox.Show("Error adding weather location"); } else { client.GetMyWeatherLocationsDetailsAsync(Settings.CachedAuthenticationToken); } }; client.RemoveWeatherLocationCompleted += (o1, e1) => { if (e1.Error != null) { if (e1.Error.GetType() == typeof(FaultException <AuthenticationFault>)) { // TODO: //GetAuthenticationToken( // new Action( // () => // { // client.GetMyStockDataAsync(Settings.CachedAuthenticationToken); // } // )); } else { MessageBox.Show(e1.Error.Message); } HideProgress(); return; } if (!e1.Result) { MessageBox.Show("Error removing weather location"); } else { client.GetMyWeatherLocationsDetailsAsync(Settings.CachedAuthenticationToken); } }; watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.Default); watcher.StatusChanged += (o1, e1) => { }; watcher.PositionChanged += (o1, e1) => { ReverseGeocodeRequest request = new ReverseGeocodeRequest() { Credentials = new Credentials() { ApplicationId = "Arz9raeGhoGWF5U5hv0Py-wnLL1ZMa82OF5BrFlSKExWfHzhlOaQ8gwBJldxi3Hg" }, Location = new Location() { Latitude = e1.Position.Location.Latitude, Longitude = e1.Position.Location.Longitude, } }; geoCodeClient.ReverseGeocodeAsync(request, e1.Position.Location); watcher.Stop(); }; geoCodeClient = new GeocodeServiceClient( GetBinding(), new EndpointAddress(new Uri("http://dev.virtualearth.net/webservices/v1/geocodeservice/GeocodeService.svc"))); geoCodeClient.ReverseGeocodeCompleted += (o1, e1) => { if (e1.Error != null) { HideProgress(); MessageBox.Show("Error resolving your location"); } else { var address = e1.Result.Results.FirstOrDefault().Address; client.GetWeatherAsync(Settings.CachedAuthenticationToken, address.Locality + ", " + address.AdminDistrict); } }; geoCodeClient.GeocodeCompleted += (o1, e1) => { if (e1.Error != null) { HideProgress(); MessageBox.Show("Error resolving your location"); } else { ListBoxSearchedLocations.ItemsSource = e1.Result.Results; } }; WeatherList.ItemsSource = weatherViewModel; weatherViewModel.CollectionChanged += (o, e) => { if (weatherViewModel.Count > 0) { NotLoadedSection.Visibility = NoItemsMessage.Visibility = Visibility.Collapsed; } if (weatherViewModel.Count == 0) { LoadingMessage.Visibility = Visibility.Collapsed; NoItemsMessage.Visibility = Visibility.Visible; } }; }
public static void ReverseGeocodeAddress(Dispatcher uiDispatcher, CredentialsProvider credentialsProvider, Location location, Action<GeocodeResult> completed = null, Action<GeocodeError> error = null) { completed = completed ?? (r => { }); error = error ?? (e => { }); // Get credentials and only then place an async call on the geocode service. credentialsProvider.GetCredentials(credentials => { var request = new ReverseGeocodeRequest() { // Pass in credentials for web services call. Credentials = credentials, Culture = CultureInfo.CurrentUICulture.Name, Location = location, // Don't raise exceptions. ExecutionOptions = new UsingBingMaps.Bing.Geocode.ExecutionOptions { SuppressFaults = true }, }; EventHandler<ReverseGeocodeCompletedEventArgs> reverseGeocodeCompleted = (s, e) => { try { if (e.Result.ResponseSummary.StatusCode != UsingBingMaps.Bing.Geocode.ResponseStatusCode.Success || e.Result.Results.Count == 0) { // Report geocode error. uiDispatcher.BeginInvoke(() => error(new GeocodeError(e))); } else { // Only report on first result. var firstResult = e.Result.Results.First(); uiDispatcher.BeginInvoke(() => completed(firstResult)); Debug.WriteLine("street=" + firstResult.Address.AddressLine.ToString()); Debug.WriteLine("admin district=" + firstResult.Address.AdminDistrict.ToString()); Debug.WriteLine("country region=" + firstResult.Address.CountryRegion.ToString()); Debug.WriteLine("district=" + firstResult.Address.District.ToString()); Debug.WriteLine("formatted addres=" + firstResult.Address.FormattedAddress.ToString()); Debug.WriteLine("locality=" + firstResult.Address.Locality.ToString()); Debug.WriteLine("postal code=" + firstResult.Address.PostalCode.ToString()); Debug.WriteLine("postal town=" + firstResult.Address.PostalTown.ToString()); CurrentAddress = firstResult.Address.FormattedAddress.ToString(); CurrentAddress_AdminDistrict = firstResult.Address.AdminDistrict.ToString(); CurrentAddress_CountryRegion = firstResult.Address.CountryRegion.ToString(); CurrentAddress_Locality = firstResult.Address.Locality.ToString(); CurrentAddress_PostalCode = firstResult.Address.PostalCode.ToString(); CurrentAddress_AddressLine = firstResult.Address.AddressLine.ToString(); } } catch (Exception ex) { uiDispatcher.BeginInvoke(() => error(new GeocodeError(ex.Message, ex))); } }; var geocodeClient = new GeocodeServiceClient(); geocodeClient.ReverseGeocodeCompleted += reverseGeocodeCompleted; geocodeClient.ReverseGeocodeAsync(request); }); }
/// <summary> /// This method will reverse geocode the ground station based on its location and /// call the callback method. /// </summary> /// <param name="name">Name of the ground station</param> /// <param name="id">id of the station</param> /// <param name="location">Location of the ground station</param> private void reverseGeocode(string name, string id, Location location) { ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest(); // Set the credentials using a valid Bing Maps key reverseGeocodeRequest.Credentials = new Credentials(); reverseGeocodeRequest.Credentials.ApplicationId = this.BingMapsKey; // Set the point to use to find a matching address GeocodeService.GeocodeLocation point = new GeocodeService.GeocodeLocation(); point.Latitude = location.Latitude; point.Longitude = location.Longitude; reverseGeocodeRequest.Location = point; // Make the reverse geocode request GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService"); geocodeService.ReverseGeocodeCompleted += new EventHandler<ReverseGeocodeCompletedEventArgs>( delegate(object sender, ReverseGeocodeCompletedEventArgs e) { this.reverseGeocodeCompleted(sender, e, name, id, location); }); geocodeService.ReverseGeocodeAsync(reverseGeocodeRequest); }
public static void ReverseGeocodeAddress(Dispatcher uiDispatcher, CredentialsProvider credentialsProvider, Location location, Action <GeocodeResult> completed = null, Action <GeocodeError> error = null) { Debug.WriteLine("inside ReverseGeocodeAddress"); completed = completed ?? (r => { }); error = error ?? (e => { }); // Get credentials and only then place an async call on the geocode service. credentialsProvider.GetCredentials(credentials => { Debug.WriteLine("inside GetCredentials"); var request = new ReverseGeocodeRequest() { // Pass in credentials for web services call. Credentials = credentials, Culture = CultureInfo.CurrentUICulture.Name, Location = location, // Don't raise exceptions. ExecutionOptions = new ScheduledTaskAgent1.Bing.Geocode.ExecutionOptions { SuppressFaults = true }, }; EventHandler <ReverseGeocodeCompletedEventArgs> reverseGeocodeCompleted = (s, e) => { try { if (e.Result.ResponseSummary.StatusCode != ScheduledTaskAgent1.Bing.Geocode.ResponseStatusCode.Success || e.Result.Results.Count == 0) { // Report geocode error. uiDispatcher.BeginInvoke(() => error(new GeocodeError(e))); } else { // Only report on first result. var firstResult = e.Result.Results[0]; uiDispatcher.BeginInvoke(() => completed(firstResult)); //Debug.WriteLine("street=" + firstResult.Address.AddressLine.ToString()); //Debug.WriteLine("admin district=" + firstResult.Address.AdminDistrict.ToString()); //Debug.WriteLine("country region=" + firstResult.Address.CountryRegion.ToString()); //Debug.WriteLine("district=" + firstResult.Address.District.ToString()); Debug.WriteLine("formatted addres=" + firstResult.Address.FormattedAddress.ToString()); //Debug.WriteLine("locality=" + firstResult.Address.Locality.ToString()); //Debug.WriteLine("postal code=" + firstResult.Address.PostalCode.ToString()); //Debug.WriteLine("postal town=" + firstResult.Address.PostalTown.ToString()); CurrentAddress = firstResult.Address.FormattedAddress.ToString(); //CurrentAddress_AdminDistrict = firstResult.Address.AdminDistrict.ToString(); //CurrentAddress_CountryRegion = firstResult.Address.CountryRegion.ToString(); //CurrentAddress_Locality = firstResult.Address.Locality.ToString(); //CurrentAddress_PostalCode = firstResult.Address.PostalCode.ToString(); //CurrentAddress_AddressLine = firstResult.Address.AddressLine.ToString(); } } catch (Exception ex) { uiDispatcher.BeginInvoke(() => error(new GeocodeError(ex.Message, ex))); } }; var geocodeClient = new GeocodeServiceClient(); geocodeClient.ReverseGeocodeCompleted += reverseGeocodeCompleted; geocodeClient.ReverseGeocodeAsync(request); }); }
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e); this.ContentPanel.DataContext = States.CurReport; switch (States.CurReport.Mood) { case ("positive"): MoodText.Text = "Happy"; break; case "negative": MoodText.Text = "Unhappy"; break; case "concerned": MoodText.Text = "Concerned"; break; } if (!(States.CurReport.Photo == "" || States.CurReport.Photo == null)) { this.PhotoHeader.Visibility = Visibility.Visible; this.PhotoContainer.Visibility = Visibility.Visible; } if (States.CurReport.Location == "" || States.CurReport.Location == "Null") { this.LocationBox.Text = "No Location Provided"; } else { GeoCoordinate location = new GeoCoordinate(); string[] coordinate = States.CurReport.Location.Split((',')); location.Latitude = Convert.ToDouble(coordinate[0]); location.Longitude = Convert.ToDouble(coordinate[1]); ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest(); // Set the credentials using a valid Bing Maps key reverseGeocodeRequest.Credentials = new Credentials(); reverseGeocodeRequest.Credentials.ApplicationId = "ApIZ31eaMUXWc4YVuYaZZSi7LdLjbtdfHWcv7n-ax0z1-ytR8z9GbRxAVyLCJFC5"; // Set the point to use to find a matching address //BingMaps.Location point = new BingMaps.Location(); //point.Latitude = location.Latitude; //point.Longitude = location.Longitude; reverseGeocodeRequest.Location = new Location(); reverseGeocodeRequest.Location.Latitude = location.Latitude; reverseGeocodeRequest.Location.Longitude = location.Longitude; // Make the reverse geocode request GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService"); geocodeService.ReverseGeocodeCompleted += new EventHandler<ReverseGeocodeCompletedEventArgs>(geocodeService_ReverseGeocodeCompleted); geocodeService.ReverseGeocodeAsync(reverseGeocodeRequest); } }
public static async Task <LocationInformation> ResolveLocationAsync(double latitude, double longitude) { LocationInformation location = null; GeocodeServiceClient geocodeClient = Helpers.BindingManager.GetGeocodeClient(); ReverseGeocodeRequest geocodeRequest = new ReverseGeocodeRequest(); // Set the credentials using a valid Bing Maps key geocodeRequest.Credentials = new GeocodeService.Credentials(); geocodeRequest.Credentials.ApplicationId = Core.Common.CoreConstants.BingLocationApiKey; // Set the full address query geocodeRequest.Location = new GeocodeService.Location() { Latitude = latitude, Longitude = longitude, }; // Set the options to only return high confidence results List <FilterBase> filters = new List <FilterBase>(); filters.Add(new ConfidenceFilter() { MinimumConfidence = GeocodeService.Confidence.High, }); GeocodeOptions geocodeOptions = new GeocodeOptions(); geocodeOptions.Filters = filters; GeocodeResponse geocodeResponse = await geocodeClient.ReverseGeocodeAsync(geocodeRequest); var result = geocodeResponse.Results.FirstOrDefault(); GeocodeService.Address foundAddress = null; GeocodeService.Location foundLocation = null; if (result != null) { foundAddress = result.Address; foundLocation = result.Locations.FirstOrDefault(); if (foundAddress != null) { location = new LocationInformation() { DisplayName = foundAddress.FormattedAddress, StreetAddress = foundAddress.AddressLine, City = foundAddress.Locality, PostalCode = foundAddress.PostalCode, State = foundAddress.AdminDistrict, County = foundAddress.District, Latitude = (foundLocation == null) ? 0.0 : foundLocation.Latitude, Longitude = (foundLocation == null) ? 0.0 : foundLocation.Longitude, }; } } return(location); }