/// <summary> /// Bing Maps Geocode服务的回调方法. /// </summary> private void GeocodeClient_ReverseGeocodeCompleted(object sender, ReverseGeocodeCompletedEventArgs e) { if (e.Error != null) { MessageBox.Show(e.Error.Message); } else if (e.Result.Results.Count > 0) { // 我们只关心第一个结果. var result = e.Result.Results[0]; Travel travel = new Travel() { // PartitionKey代表用户. // 然而, 客户端可以如下演示般发送一个假身份. // 为了防止客户端使用假身份, // 我们的服务一直在服务器端查询真实的身份. PartitionKey = "*****@*****.**", RowKey = Guid.NewGuid(), Place = result.DisplayName, Time = DateTime.Now, // Latitude/Longitude通过服务获得地址, // 因此可能不是正巧为所点击的地址 Latitude = result.Locations[0].Latitude, Longitude = result.Locations[0].Longitude }; // 添加到ObservableCollection. this._travelItems.Add(travel); this._dataServiceContext.AddObject("Travels", travel); } }
/// <summary> /// Callback method for the Bing Maps Geocode service. /// </summary> private void GeocodeClient_ReverseGeocodeCompleted(object sender, ReverseGeocodeCompletedEventArgs e) { if (e.Error != null) { MessageBox.Show(e.Error.Message); } else if (e.Result.Results.Count > 0) { // We only care about the first result. var result = e.Result.Results[0]; Travel travel = new Travel() { // The PartitionKey represents the user. // However, the client can send a fake identity as demonstrated below. // To prevent clients faking the identity, // our service always queries for the real identity on the service side. PartitionKey = "*****@*****.**", RowKey = Guid.NewGuid(), Place = result.DisplayName, Time = DateTime.Now, // Latitude/Longitude is obtained from the service, // so it may not be the exact clicked position. Latitude = result.Locations[0].Latitude, Longitude = result.Locations[0].Longitude }; // Add to the ObservableCollection. App.DataSource.AddToTravel(travel); } }
/// <summary> /// Bing Maps Geocode服务的回调方法. /// </summary> private void GeocodeClient_ReverseGeocodeCompleted(object sender, ReverseGeocodeCompletedEventArgs e) { if (e.Error != null) { MessageBox.Show(e.Error.Message); } else if (e.Result.Results.Count > 0) { // 我们只关心第一个结果. var result = e.Result.Results[0]; Travel travel = new Travel() { // PartitionKey代表用户. // 然而, 客户端可以如下演示般发送一个假身份. // 为了防止客户端使用假身份, // 我们的服务一直在服务器端查询真实的身份. PartitionKey = "*****@*****.**", RowKey = Guid.NewGuid(), Place = result.DisplayName, Time = DateTime.Now, // Latitude/Longitude通过服务获得地址, // 因此可能不是正巧为所点击的地址. Latitude = result.Locations[0].Latitude, Longitude = result.Locations[0].Longitude }; // 添加到ObservableCollection. App.DataSource.AddToTravel(travel); } }
internal GeocodeError(ReverseGeocodeCompletedEventArgs e) { if (e.Result == null || e.Result.ResponseSummary == null || string.IsNullOrEmpty(e.Result.ResponseSummary.FaultReason)) { Reason = NoResults; } else { Reason = e.Result.ResponseSummary.FaultReason; } Exception = e.Error; }
void geocodeService_ReverseGeocodeCompleted(object sender, ReverseGeocodeCompletedEventArgs e) { if (e.Cancelled || e.Error != null || e.Result.ResponseSummary.StatusCode != ResponseStatusCode.Success) { MessageBox.Show("Unable to complete the ReverseGeocode request"); return; } GeocodeResponse response = e.Result; if (response.Results.Count > 0) { GeocodeResult address = response.Results[0]; MessageBox.Show(address.DisplayName); } }
/// <summary> /// This method will be called upon completion of the reverse geocoding. On completion /// this ground station will be sent to be mapped by using the correct ISO country code. /// </summary> /// <param name="sender">sender</param> /// <param name="e">Results of the reverse geocoding</param> /// <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 reverseGeocodeCompleted(object sender, ReverseGeocodeCompletedEventArgs e, string name, string id, Location location) { string country = ""; try { // Get the country code from the results country = e.Result.Results[0].Address.CountryRegion.ToLower(); // Add the ground station locations to the map this.mapGroundStation(name, id, location, countryMap[country]); } catch { // Error was found, due to lack of time just place it to be european union this.mapGroundStation(name, id, location, "europeanunion"); } }
private void lookupAddress_ReverseGeocodeCompleted(object sender, ReverseGeocodeCompletedEventArgs e) { //throw new NotImplementedException(); if (e.Result == null || e.Result.Results == null || !e.Result.Results.Any()) { return; } Address found = null; foreach (GeocodeResult l in e.Result.Results) { if (l.Confidence == Confidence.High) { found = l.Address; _gcw.Stop(); break; } } if (found == null) { foreach (GeocodeResult l in e.Result.Results) { if (l.Confidence == Confidence.Medium) { found = l.Address; break; } } } try { if (found == null) { found = e.Result.Results.FirstOrDefault().Address; } } catch { return; } SetCurrentAddress(found); }
private void _ReverseGeocodeCompleted(object sender, ReverseGeocodeCompletedEventArgs e) { AsyncCompletedEventArgs outArgs = null; if (IsAsyncCompleted(sender, e, out outArgs)) { PropertySet result = null; if (!outArgs.Cancelled && outArgs.Error == null) { result = e.Result; } if (ReverseGeocodeCompleted != null) { ReverseGeocodeCompleted(this, new ReverseGeocodeCompletedEventArgs( new object[1] { result }, outArgs.Error, outArgs.Cancelled, outArgs.UserState)); } } }
private void geocodeClient_ReverseGeocodeCompleted(object sender, ReverseGeocodeCompletedEventArgs e) { if (e.Error == null) { if (e.Result.Results != null && e.Result.Results.Count != 0) { int i = 0; foreach (var item in e.Result.Results) { if (item.Address.AddressLine != "") { i++; double latitude = e.Result.Results.First().Locations.First().Latitude; double longitude = e.Result.Results.First().Locations.First().Longitude; currentNearby = new GeoCoordinate(latitude, longitude); // Remove (house) numbers from address string address = item.Address.AddressLine; address = Regex.Replace(address, @"[\d-]", string.Empty).Trim(); // Check if address already searched if (!nearbyStreets.Contains(address)) { nearbyStreets.Add(address); searcher.searchNewsByAddress("\"" + address + "\""); break; } else { tryNextNearbyLocation(); } } } if (i == 0) { tryNextNearbyLocation(); } } else { tryNextNearbyLocation(); } } else { currentNearby = null; tryNextNearbyLocation(); } }
/// <summary> /// React on reverse geocode completed. /// </summary> /// <param name="sender">Ignored.</param> /// <param name="e">Reverse geocode completed event args.</param> private void _ReverseGeocodeCompleted(object sender, ReverseGeocodeCompletedEventArgs e) { if (!e.Cancelled && e.Error == null) { // Geocoded successfully. PropertySet set = e.Result; // WORKAROUND!!! TODO DT // Remove, when geocode service will return good response in case if it // hasn't found candidates by reverse geocoding. // Right now it can return different responses. try { // In ArcGIS Server 10 exception is not throws on failed reverse geocoding. // Server returns empty result. if (set.PropertyArray != null) { Address address = _GetAddress(set); // WORKAROUND!!! // When service return point without address - do not show anything. if (string.IsNullOrEmpty(address.AddressLine)) return; PointN point = (PointN)e.Result.PropertyArray[0].Value; ESRI.ArcGIS.Client.Geometry.MapPoint location = new ESRI.ArcGIS.Client.Geometry.MapPoint( point.X, point.Y); if (AsyncReverseGeocodeCompleted != null) AsyncReverseGeocodeCompleted(this, new AsyncReverseGeocodedEventArgs(address, location, e.UserState)); } } catch (Exception ex) { } } }
void geocodeService_ReverseGeocodeCompleted(object sender, ReverseGeocodeCompletedEventArgs e) { string s = string.Format("{0}{2}", e.Result.Results[0].Address.AddressLine, System.Environment.NewLine, e.Result.Results[0].Address.Locality); if (s == "") { this.LocationBox.Text = "Cannot Resolve Address"; } else { this.LocationBox.Text = string.Format("{0}{1}{2}", e.Result.Results[0].Address.AddressLine, System.Environment.NewLine, e.Result.Results[0].Address.Locality); } }
private void lookupAddress_ReverseGeocodeCompleted(object sender, ReverseGeocodeCompletedEventArgs e) { //throw new NotImplementedException(); if (e.Result == null || e.Result.Results == null || !e.Result.Results.Any()) return; Address found = null; foreach (GeocodeResult l in e.Result.Results) { if (l.Confidence == Confidence.High) { found = l.Address; _gcw.Stop(); break; } } if (found == null) { foreach (GeocodeResult l in e.Result.Results) { if (l.Confidence == Confidence.Medium) { found = l.Address; break; } } } try { if (found == null) found = e.Result.Results.FirstOrDefault().Address; } catch { return; } SetCurrentAddress(found); }