public async Task <GeoAddress> DecodeAsync( double latitude, double longitude, CancellationToken cancellationToken) { ReverseGeocodeRequest request = new ReverseGeocodeRequest(); request.BingMapsKey = _options.ApiKey; request.Point = new Coordinate() { Latitude = latitude, Longitude = longitude }; request.IncludeIso2 = true; request.IncludeNeighborhood = true; request.IncludeEntityTypes = new List <EntityType>() { EntityType.Address, EntityType.CountryRegion, EntityType.Postcode1, EntityType.PopulatedPlace, EntityType.Neighborhood, EntityType.AdminDivision1, EntityType.AdminDivision2 }; Response res = await ServiceManager.GetResponseAsync(request); if (res.StatusCode == 200) { List <Location> locations = GetLocationsFromBingResponse(res); return(GetAddressFromLocations(locations)); } return(null); }
public async Task <String> getAddress(Coordinate point) { //Create a request. var request = new ReverseGeocodeRequest() { Point = point, IncludeIso2 = true, IncludeNeighborhood = true, BingMapsKey = "Alvpuc-Z8ROrtuOcQZdVD1iaINzybihaHRnSHYWL8jwdEjVrXRj843L8ayxchoj7" }; //Process the request by using the ServiceManager. var response = await ServiceManager.GetResponseAsync(request); if (response != null && response.ResourceSets != null && response.ResourceSets.Length > 0 && response.ResourceSets[0].Resources != null && response.ResourceSets[0].Resources.Length > 0) { var result = response.ResourceSets[0].Resources[0] as BingMapsRESTToolkit.Location; return(result.Address.FormattedAddress); } return(null); }
/// <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); }
/// <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); } }
public async Task <ReverseGeocodeResponse> ReverseGeocode(double lat, double lng) { string result = ""; using (var client = new HttpClient()) { MyLocation location = new MyLocation(); location.Lat = lat; location.Lng = lng; var root = new ReverseGeocodeRequest(); root.Location = location; var settings = new JsonSerializerSettings(); settings.ContractResolver = new LowercaseSerializer(); var json = JsonConvert.SerializeObject(root, Formatting.Indented, settings); var data = new StringContent(json, Encoding.UTF8, "application/json"); var url = "https://siteapi.cloud.huawei.com/mapApi/v1/siteService/reverseGeocode?key=" + Android.Net.Uri.Encode(ApiKey); var response = await client.PostAsync(url, data); result = response.Content.ReadAsStringAsync().Result; } return(JsonConvert.DeserializeObject <ReverseGeocodeResponse>(result)); }
private void radMap_MapMouseDoubleClick(object sender, MapMouseRoutedEventArgs e) { ReverseGeocodeRequest reverseRequest = new ReverseGeocodeRequest(); reverseRequest.Location = e.Location; this.geocodeProvider.ReverseGeocodeAsync(reverseRequest); }
public static ReverseGeocodeRequest CreateReverseGeocodeRequest(Microsoft.Maps.MapControl.Location location, string credentials) { var request = new ReverseGeocodeRequest(); request.Credentials = new Microsoft.Maps.MapControl.Credentials() { Token = credentials }; request.Location = new Microsoft.Maps.MapControl.Location() { Latitude = location.Latitude, Longitude = location.Longitude, Altitude =location.Altitude }; return request; }
private Dictionary <string, string> buildQueryString(ReverseGeocodeRequest r) { var c = new Dictionary <string, string>(); // We only support JSON c.AddIfSet("format", format); c.AddIfSet("key", key); c.AddIfSet("lat", r.Latitude?.ToString(CultureInfo.InvariantCulture.NumberFormat)); c.AddIfSet("lon", r.Longitude?.ToString(CultureInfo.InvariantCulture.NumberFormat));; c.AddIfSet("zoom", r.ZoomLevel); c.AddIfSet("addressdetails", r.BreakdownAddressElements); c.AddIfSet("namedetails", r.ShowAlternativeNames); // let's use english instead of prefer language that will be the same language as the the chosen country //c.AddIfSet("accept-language", r.PreferredLanguages); c.AddIfSet("accept-language", "en"); c.AddIfSet("countrycodes", r.CountryCodeSearch); c.AddIfSet("polygon_geojson", r.ShowGeoJSON); c.AddIfSet("polygon_kml", r.ShowKML); c.AddIfSet("polygon_svg", r.ShowSVG); c.AddIfSet("polygon_text", r.ShowPolygonText); c.AddIfSet("extratags", r.ShowExtraTags); return(c); }
private string ReverseGeocodePoint(string locationString) { string results = ""; string key = "ArLeGdHOcc5h7j3L4W37oFGcU9E-LF3tAZi4o0DfhXbPJ8aiyTGbIDNHex08R2u7"; 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(); string[] digits = locationString.Split(','); point.Latitude = double.Parse(digits[0].Trim()); point.Longitude = double.Parse(digits[1].Trim()); reverseGeocodeRequest.Location = point; // Make the reverse geocode request GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService"); GeocodeResponse geocodeResponse = geocodeService.ReverseGeocode(reverseGeocodeRequest); if (geocodeResponse.Results.Length > 0) { results = geocodeResponse.Results[0].DisplayName; } else { results = "No Results found"; } return(results); }
public GeocodeResponse ReverseGeocode([System.Xml.Serialization.XmlElementAttribute(IsNullable = true)] ReverseGeocodeRequest request) { object[] results = this.Invoke("ReverseGeocode", new object[] { request }); return((GeocodeResponse)(results[0])); }
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 void ReverseGeocodeAsync(ReverseGeocodeRequest request, object userState) { if ((this.ReverseGeocodeOperationCompleted == null)) { this.ReverseGeocodeOperationCompleted = new System.Threading.SendOrPostCallback(this.OnReverseGeocodeCompleted); } this.InvokeAsync("ReverseGeocode", new object[] { request }, this.ReverseGeocodeOperationCompleted, userState); }
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); }); }
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); }
/// <summary> /// Esta funcion busc a travez de la latitud y la longitud la direccion correspondiente /// Devolviendo un objeto de tipo LocalizadorData con los datos correspondienes. /// </summary> /// <param name="lat"></param> /// <param name="lon"></param> /// <returns>new LocalizadorData</returns> public static LocalizadorData Find(double lat, double lon) { LocalizadorData LD = new LocalizadorData(); ReverseGeocodeRequest g = new ReverseGeocodeRequest(); GeocodeResponse r = new GeocodeResponse(); ReverseGeocoder RG = new ReverseGeocoder(); g.Latitude = lat; g.Longitude = lon; Task <GeocodeResponse> rs = RG.ReverseGeocode(g); r = rs.Result; LD.calle = r.Address.Road; return(LD); }
public static ReverseGeocodeRequest GetReverseRequest(double lat, double lon) { ReverseGeocodeRequest reverseRequest = new ReverseGeocodeRequest(); reverseRequest.Credentials = new Credentials(); reverseRequest.Credentials.ApplicationId = KEY; Location point = new Location(); point.Latitude = lat; point.Longitude = lon; reverseRequest.Location = point; return(reverseRequest); }
/// <summary> /// Demostrates how to make a Reverse Geocode Request. /// </summary> private void ReverseGeocodeBtn_Clicked(object sender, RoutedEventArgs e) { var r = new ReverseGeocodeRequest() { Point = new Coordinate(45, -110), IncludeEntityTypes = new List <EntityType>() { EntityType.AdminDivision1, EntityType.CountryRegion }, IncludeNeighborhood = true, IncludeIso2 = true, BingMapsKey = BingMapsKey }; ProcessRequest(r); }
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); } }
private string ReverseGeocodePoint(string locationString) { string results = ""; string key = "Am_qwaGQRh4tOT1wCX_lWd2EzqKl1_PuXjX9nuMQZFWehKYgcXqT99avIJhvAGmx"; 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(); string[] digits = locationString.Split(','); if (digits.Length == 2 && digits[0].Length > 0 && digits[1].Length > 0) { point.Latitude = double.Parse(digits[0].Trim()); point.Longitude = double.Parse(digits[1].Trim()); reverseGeocodeRequest.Location = point; // Make the reverse geocode request GeocodeServiceClient geocodeService = new GeocodeServiceClient(); GeocodeResponse geocodeResponse = geocodeService.ReverseGeocode(reverseGeocodeRequest); if (geocodeResponse.Results.Length > 0) { results = geocodeResponse.Results[0].DisplayName; } else { results = "Location data not available"; } return(results); } else { return("Location data not available"); } }
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); } }
public static async Task <Location> GetRevGeo(Double inlong, Double inlat) { Location retad = new Location(); Coordinate secoord = new Coordinate(); secoord.Latitude = inlat; secoord.Longitude = inlong; var request = new ReverseGeocodeRequest() { IncludeIso2 = true, IncludeNeighborhood = false, BingMapsKey = bmkey, Point = secoord }; try { var response = await request.Execute(); if (response != null && response.ResourceSets != null && response.ResourceSets.Length > 0 && response.ResourceSets[0].Resources != null && response.ResourceSets[0].Resources.Length > 0) { var qresult = response.ResourceSets[0].Resources[0] as BingMapsRESTToolkit.Location; retad = qresult; } else { retad = null; } } catch { retad = null; } return(retad); }
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); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("GetAddress"); string slat = req.Query["latitude"]; string slon = req.Query["longitude"]; if (double.TryParse(slat.Replace(',', '.'), out var lat) && double.TryParse(slon.Replace(',', '.'), out var lon)) { ReverseGeocodeRequest rq = new ReverseGeocodeRequest { Point = new Coordinate(lat, lon) }; try { var response = await rq.Execute(); if (response.StatusCode == 200) { var rss = JsonSerializer.Serialize(response.ResourceSets); log.LogInformation("ResourceSets: {0}", rss); var loc = response.ResourceSets[0].Resources[0] as Location; return(new OkObjectResult(loc.Address)); } else { return(new BadRequestObjectResult(response.StatusDescription)); } } catch (Exception) { return(new BadRequestObjectResult($"Failed to get address for coordinats {slat}, {slon}")); } } return(new BadRequestObjectResult($"Invalid coordinates {slat}, {slon}!")); }
private void RetrieveFormatedAddressFromBing(double lat, double lng) { string results = string.Empty; try { ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest(); // Set the credentials using a valid Bing Maps key reverseGeocodeRequest.Credentials = new BingMapsGeocode.Credentials(); reverseGeocodeRequest.Credentials.ApplicationId = "Agc9SoSDINTGiryq7Ns1ddNUS3sQQLXT4eQqXGhkDka9QkMxfudjMs9k5wwPEhDI"; // Set the point to use to find a matching address BingMapsGeocode.Location point = new BingMapsGeocode.Location(); point.Latitude = lat; point.Longitude = lng; reverseGeocodeRequest.Location = point; // Make the reverse geocode request GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService"); GeocodeResponse geocodeResponse = geocodeService.ReverseGeocode(reverseGeocodeRequest); if (geocodeResponse.Results != null) { Street = geocodeResponse.Results[0].Address.AddressLine; City = geocodeResponse.Results[0].Address.Locality; State = geocodeResponse.Results[0].Address.AdminDistrict; Zip = geocodeResponse.Results[0].Address.PostalCode; Country = geocodeResponse.Results[0].Address.CountryRegion; Debug.WriteLine("{0}, {1}, {2}, {3}, {4}", Street, City, State, Zip, Country); } //geocodeService.ReverseGeocodeCompleted += new EventHandler<ReverseGeocodeCompletedEventArgs>(geocodeService_ReverseGeocodeCompleted); //geocodeService.ReverseGeocodeAsync(reverseGeocodeRequest); } catch (Exception ex) { throw new MyLoException(ex.Message); } }
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 Dictionary <string, string> buildQueryString(ReverseGeocodeRequest r) { var c = new Dictionary <string, string>(); // We only support JSON c.AddIfSet("format", format); c.AddIfSet("key", key); c.AddIfSet("lat", r.Latitude); c.AddIfSet("lon", r.Longitude); c.AddIfSet("zoom", r.ZoomLevel); c.AddIfSet("addressdetails", r.BreakdownAddressElements); c.AddIfSet("namedetails", r.ShowAlternativeNames); c.AddIfSet("accept-lanauage", r.PreferredLanguages); c.AddIfSet("countrycodes", r.CountryCodeSearch); c.AddIfSet("polygon_geojson", r.ShowGeoJSON); c.AddIfSet("polygon_kml", r.ShowKML); c.AddIfSet("polygon_svg", r.ShowSVG); c.AddIfSet("polygon_text", r.ShowPolygonText); c.AddIfSet("extratags", r.ShowExtraTags); return(c); }
public static async Task <MEPModel.Location> reversegeocode(double latitude, double longitude) { BingMapsRESTToolkit.Location result = null; ReverseGeocodeRequest request = new ReverseGeocodeRequest() { Point = new Coordinate(latitude, longitude), BingMapsKey = Settings1.Default.BingKey }; var response = await ServiceManager.GetResponseAsync(request); if (response != null && response.ResourceSets != null && response.ResourceSets.Length > 0 && response.ResourceSets[0].Resources != null && response.ResourceSets[0].Resources.Length > 0) { result = response.ResourceSets[0].Resources[0] as BingMapsRESTToolkit.Location; //this.searchlocation = //var b = searchlocation.BoundingBox; //myMap.SetView(new Microsoft.Maps.MapControl.WPF.LocationRect(b[0], b[1], b[2], b[3])); } return(new MEPModel.Location(latitude, longitude, result.Address.AddressLine, result.Address.PostalCode, result.Address.Locality, result.Address.CountryRegion)); }
/// <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 string GeocodeReverseLookup(string latLong) { var bingMapApiKey = ConfigurationManager.AppSettings["BingMapCredentials"]; var point = new Location(); var latLongValue = latLong.Split(','); point.Latitude = double.Parse(latLongValue[0].Trim()); point.Longitude = double.Parse(latLongValue[1].Trim()); var reverseGeocodeRequest = new ReverseGeocodeRequest { Credentials = new Credentials { ApplicationId = bingMapApiKey }, Location = point }; var geocodeService = new GeocodeServiceClient(); var geocodeResponse = geocodeService.ReverseGeocode(reverseGeocodeRequest); if(geocodeResponse.Results.Length > 0) { return geocodeResponse.Results[0].DisplayName; } return null; }
public ActionResult <FirstAid> SaveForm(FirstAidDTO dto) { FirstAid firstAid = dto; ReverseGeocoder y = new ReverseGeocoder(); var t = new ReverseGeocodeRequest { Latitude = firstAid.latitude, Longitude = firstAid.longitude, PreferredLanguages = "en", }; Task <GeocodeResponse> r2 = y.ReverseGeocode(t); GeocodeResponse resp = r2.Result; firstAid.country = resp.Address.Country; firstAid.NullToDefault(); _context.FirstAid.Add(firstAid); _context.SaveChanges(); var id = _context.FirstAid.OrderByDescending(x => x.id).FirstOrDefault().id; if (id == null) { return(NotFound()); } if (dto.injury != null && dto.injury.Count() > 0) { var injuries = _context.Injury.ToList(); foreach (var injury in dto.injury) { var inj = injuries.FirstOrDefault(x => x.name.Equals(injury)); if (inj != null) { _context.Add(new Fainjury((int)id, inj.id)); } } } if (dto.assistance != null && dto.assistance.Count() > 0) { var assistances = _context.Assistance.ToList(); foreach (var assistance in dto.assistance) { var ass = assistances.FirstOrDefault(x => x.name.Equals(assistance)); if (ass != null) { _context.Add(new Faassistance((int)id, ass.id)); } } } if (dto.phType != null && dto.phType.Count() > 0) { var phTypes = _context.PhType.ToList(); foreach (var phType in dto.phType) { var ph = phTypes.FirstOrDefault(x => x.name.Equals(phType)); if (ph != null) { _context.Add(new FaphType((int)id, ph.id)); } } } _context.SaveChanges(); return(firstAid); }
private void GeocodeHandler(object sender, RoutedEventArgs e) { ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest(); reverseGeocodeRequest.Location = geocodeLocation; this.geocodeProvider.ReverseGeocodeAsync(reverseGeocodeRequest); }
private string ReverseGeocodePoint(string locationString) { string results = ""; string key = "ArLeGdHOcc5h7j3L4W37oFGcU9E-LF3tAZi4o0DfhXbPJ8aiyTGbIDNHex08R2u7"; 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(); string[] digits = locationString.Split(','); point.Latitude = double.Parse(digits[0].Trim()); point.Longitude = double.Parse(digits[1].Trim()); reverseGeocodeRequest.Location = point; // Make the reverse geocode request GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService"); GeocodeResponse geocodeResponse = geocodeService.ReverseGeocode(reverseGeocodeRequest); if (geocodeResponse.Results.Length > 0) results = geocodeResponse.Results[0].DisplayName; else results = "No Results found"; return results; }
public string ReverseGeocodePoint(string locationString) { string results = ""; 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(); string[] digits = locationString.Split(','); point.Latitude = double.Parse(digits[0].Trim()); point.Longitude = double.Parse(digits[1].Trim()); reverseGeocodeRequest.Location = point; // Make the reverse geocode request GeocodeServiceClient geocodeService = new GeocodeServiceClient(); GeocodeResponse geocodeResponse = geocodeService.ReverseGeocode(reverseGeocodeRequest); if (geocodeResponse.Results.Length > 0) results = geocodeResponse.Results[0].DisplayName; else results = "No Results found"; return results; }
public System.IAsyncResult BeginReverseGeocode(ReverseGeocodeRequest request, System.AsyncCallback callback, object asyncState) { return(this.BeginInvoke("ReverseGeocode", new object[] { request }, callback, asyncState)); }
/// <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 Button_Click(object sender, RoutedEventArgs e) { #if SILVERLIGHT var parentWindow = (sender as Button).ParentOfType<ChildWindow>(); #else var parentWindow = (sender as Button).ParentOfType<Window>(); #endif if (parentWindow != null) { ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest(); reverseGeocodeRequest.Location = geocodeLocation; this.geocodeProvider.ReverseGeocodeAsync(reverseGeocodeRequest); parentWindow.Close(); } }
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 void ReverseGeocodeAsync(ReverseGeocodeRequest request) { this.ReverseGeocodeAsync(request, null); }
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); }
/// <summary> /// Attempt to get an address or location from a set of coordinates /// </summary> /// <param name="req">Reverse geocode request object</param> /// <returns>A single reverse geocode response</returns> public async Task <GeocodeResponse> ReverseGeocode(ReverseGeocodeRequest req) { var result = await WebInterface.GetRequest <GeocodeResponse>(url, buildQueryString(req)).ConfigureAwait(false); return(result); }
private void getAddressFromPoint(double latitude, double longitude) { ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest() { Credentials = new Credentials() { ApplicationId = BingMapKey }, Location = new Location() { Latitude = latitude, Longitude = longitude } }; GeocodeService.GeocodeServiceClient geocodeService = new GeocodeService.GeocodeServiceClient("BasicHttpBinding_IGeocodeService"); try { geocodeService.ReverseGeocodeAsync(reverseGeocodeRequest); geocodeService.ReverseGeocodeCompleted += geocodeService_ReverseGeocodeCompleted; } catch (EndpointNotFoundException e) { geocodeService.Abort(); } }
public string ReverseGeocodePoint( string locationString ) { try { string results = ""; string key = "AplxUm9o3hkw6qCXBbp61H7HYlDrz-qz8ldgKLJ8Udjd8MFNJAfxxy2IWrfd4bw8"; 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(); string[] digits = locationString.Split(','); point.Latitude = double.Parse(digits[0].Trim()); point.Longitude = double.Parse(digits[1].Trim()); reverseGeocodeRequest.Location = point; // Make the reverse geocode request GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService"); GeocodeResponse geocodeResponse = geocodeService.ReverseGeocode(reverseGeocodeRequest); if (geocodeResponse.Results.Length > 0) results = geocodeResponse.Results[0].DisplayName; else results = "No Results found"; return results; } catch (Exception ex) { return ex.Message; } }
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); }); }
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; } }
void geoTimer_Tick(object sender, EventArgs e) { if (ClientIslem.geoDurum) if (ClientIslem.geoIndexList.Count > 0) { int i = ClientIslem.geoIndexList[0]; ClientIslem.geoIndex = i; if (Entities.AracDataList[i].Data != null) if (Entities.AracDataList[i].Data.DT_ENLEM.Length > 1) { Double en = Double.Parse(Entities.AracDataList[i].Data.DT_ENLEM); Double boy = Double.Parse(Entities.AracDataList[i].Data.DT_BOYLAM); Location location = new Location(en, boy); ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest(); reverseGeocodeRequest.Location = location; ClientIslem.geoDurum = false; ClientIslem.geoProvider.ReverseGeocodeAsync(reverseGeocodeRequest); List<int> bos = new List<int>(); for (int j = 1;j<ClientIslem.geoIndexList.Count; j++) bos.Add(ClientIslem.geoIndexList[j]); ClientIslem.geoIndexList = bos; } } }