public JsonResult SearchAreaForNewArea(string parentAreaID, string countryUrlPart, string locality) { var country = AppLookups.Country(countryUrlPart); Guid parentID; Area parentArea = default(Area); if (Guid.TryParse(parentAreaID, out parentID)) { parentArea = geoSvc.GetAreaByID(parentID); } List <GeocodeResult> results = new List <GeocodeResult>(); if (parentArea == default(Area)) { results = new GeocodeService().Geocode(country, locality); } else { //-- we need to blur the geography otherwise places that are coast to the coast fail... SqlGeography blurredGeo = parentArea.Geo.STBuffer(1500); //-- 1.5Km buffer zone results = new GeocodeService().Geocode(country, locality, blurredGeo); } if (results.Count == 0) { return(Json(new { Success = false })); } else { return(Json(new { Success = true, Results = results })); } }
void proxy_ReverseGeocodeCompleted(object sender, GeocodeService.ReverseGeocodeCompletedEventArgs e) { // e.Result.Results[0].Address.District = "BY" //proxy.ReverseGeocodeCompleted -= proxy_ReverseGeocodeCompleted; if (ResolveAddressCompleted != null) { ResolveAddressCompleted(sender, new ResolveAddressCompletedEventArgs( e.Result != null ? new CivicAddress() { AddressLine1 = e.Result.Results[0].Address.AddressLine, AddressLine2 = e.Result.Results[0].Address.FormattedAddress, Building = "", City = e.Result.Results[0].Address.Locality, CountryRegion = e.Result.Results[0].Address.CountryRegion, FloorLevel = "0", PostalCode = e.Result.Results[0].Address.PostalCode, StateProvince = e.Result.Results[0].Address.PostalTown } : null, e.Error, e.Cancelled, e.UserState) ); } }
public Location GetLatitudeAndLongitude(string locationName) { var geocoder = new GeocodeService(); // geocode the location of the White House return(geocoder.GeocodeLocation(locationName)); }
public LocationSelectionPage() { InitializeComponent(); var geoCodeService = new GeocodeService(); var fetchCurrentLocationCommand = new FetchCurrentLocationCommand(Plugin.Geolocator.CrossGeolocator.Current); _viewModel = new LocationSelectionViewModel(geoCodeService, fetchCurrentLocationCommand); BindingContext = _viewModel; }
public void Arrange() { _logger = new Mock <ILogger <IGeocodeService> >(); _retryWebRequest = new Mock <IRetryWebRequests>(); _postcodeApiConfiguration = new Mock <IPostcodeApiConfiguration>(); _postcodeApiConfiguration.Setup(s => s.Url).Returns("http://test.com"); sut = new GeocodeService(_logger.Object, _retryWebRequest.Object, _postcodeApiConfiguration.Object); }
public void IsLocationIncludes_Bing_ShouldBeTrue() { var service = new GeocodeService("AinYG_Q_noj6lfOQmtIBK49BEWWi1D_QSBt5fFCHxGQZFfKNSfwAM30W2mGlwhFj", GeocoderNames.Bing); var location = service.GetLocationAsync("35801 usa").Result.FirstOrDefault(); var innerLocation = service.GetLocationAsync("1405 Big Cove Rd SE").Result.FirstOrDefault(); var radius = service.GetRadius(location); var isIncludes = service.IsLocationIncludes(location.Bounds, innerLocation.Location, radius); isIncludes.Should().BeTrue(); }
public void FindAddressCandidatesWithoutTokenReturnsSuccess() { GeocodeParameters gcParams = CreateTestGeocodeParamsSingleLineBasic(); GeocodeService service = new GeocodeService(); GeocodeResult result = service.FindAddressCandidates(gcParams); Assert.IsInstanceOfType(result, typeof(GeocodeResult)); Assert.IsNotNull(result.candidates, "Candidates should not be null."); Assert.IsNotNull(result.spatialReference, "Spatial Reference should not be null."); }
public void IsLocationIncludes_Bing_ShouldBeFalse() { var service = new GeocodeService("AinYG_Q_noj6lfOQmtIBK49BEWWi1D_QSBt5fFCHxGQZFfKNSfwAM30W2mGlwhFj", GeocoderNames.Bing); var location = service.GetLocationAsync("72201 usa").Result.FirstOrDefault(); var innerLocation = service.GetLocationAsync("521 Jack Stephens Dr, Little Rock, AR 72205, США").Result.FirstOrDefault(); var radius = service.GetRadius(location); var isIncludes = service.IsLocationIncludes(location.Bounds, innerLocation.Location, radius); isIncludes.Should().BeFalse(); }
public void IsLocationIncludes_Google_ShouldBeTrue() { var service = new GeocodeService("AIzaSyDXrRQME2vYtdi94sWJV33Cl3A4mESSAXA", GeocoderNames.Google); var location = service.GetLocationAsync("35801 usa").Result.FirstOrDefault(); var innerLocation = service.GetLocationAsync("1405 Big Cove Rd SE").Result.FirstOrDefault(); var radius = service.GetRadius(location); var isIncludes = service.IsLocationIncludes(location.Bounds, innerLocation.Location, radius); isIncludes.Should().BeTrue(); }
public void IsLocationIncludes_Google_ShouldBeFalse() { var service = new GeocodeService("AIzaSyDXrRQME2vYtdi94sWJV33Cl3A4mESSAXA", GeocoderNames.Google); var location = service.GetLocationAsync("72201 usa").Result.FirstOrDefault(); var innerLocation = service.GetLocationAsync("521 Jack Stephens Dr, Little Rock, AR 72205, США").Result.FirstOrDefault(); var radius = service.GetRadius(location); var isIncludes = service.IsLocationIncludes(location.Bounds, innerLocation.Location, radius); isIncludes.Should().BeFalse(); }
private static async Task example() { var inicio = DateTime.Now; var geocode = await GeocodeService.GetGeoCode(40.670602, -73.937918); var total = (DateTime.Now - inicio).TotalMilliseconds; Console.WriteLine("Tiempo total consumir :" + Convert.ToString(total)); Console.ReadLine(); example().GetAwaiter().GetResult(); }
public JsonResult SearchAreaForNewLocationIndoor(string countryUrlPart, string locality) { //-- Step 1) Make a GeoCoding call to Bing var country = AppLookups.Country(countryUrlPart); List <GeocodeResult> results = new GeocodeService().Geocode(country, locality); if (results.Count == 0) { return(Json(new { Success = false })); } return(Json(new { Success = true, Results = results })); }
public void FindAddressCandidatesMultiLineFull() { GeocodeParameters gcParams = CreateTestGeocodeParamsMultiFieldFull(); Dictionary <string, object> dictOutput = gcParams.ToDictionary(); var test = dictOutput.ToQueryString(); Assert.IsInstanceOfType(test, typeof(string), test); GeocodeService service = new GeocodeService(); GeocodeResult result = service.FindAddressCandidates(gcParams, this.Token); Assert.IsInstanceOfType(result, typeof(GeocodeResult)); Assert.IsNotNull(result.candidates, "Candidates should not be null."); Assert.IsNotNull(result.spatialReference, "Spatial Reference should not be null."); }
public void FindAddressCandidatesWithoutTokenForStorageThrowsException() { GeocodeParameters gcParams = CreateTestGeocodeParamsSingleLineBasic(); gcParams.forStorage = true; GeocodeService service = new GeocodeService(); try { GeocodeResult result = service.FindAddressCandidates(gcParams); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(GeocodeException)); } }
public void FindAddressCandidatesSingleLineBasic() { string singleLineBasicJson = "singleLine=614+E+Gorham+St&location=%5b-89.383%2c43.081%5d&outFields=NAME&forStorage=False&locationType=rooftop&f=json"; GeocodeParameters gcParams = CreateTestGeocodeParamsSingleLineBasic(); Dictionary <string, object> dictOutput = gcParams.ToDictionary(); string queryString = dictOutput.ToQueryString(); Assert.IsInstanceOfType(queryString, typeof(string), queryString); Assert.AreEqual(queryString, singleLineBasicJson); GeocodeService service = new GeocodeService(); GeocodeResult result = service.FindAddressCandidates(gcParams, this.Token); Assert.IsInstanceOfType(result, typeof(GeocodeResult)); Assert.IsNotNull(result.candidates, "Candidates should not be null."); Assert.IsNotNull(result.spatialReference, "Spatial Reference should not be null."); }
public void FindAddressCandidatesMultiLineBasic() { string multiLineBasicJson = "address=James+Madison+Park&address2=614+E+Gorham+St&address3=Basketball+courts&neighborhood=Downtown&city=Madison&subregion=Dane+County®ion=WI&postal=53703&countryCode=USA&location=%5b-89.383%2c43.081%5d&forStorage=False&locationType=rooftop&f=json"; GeocodeParameters gcParams = CreateTestGeocodeParamsMultiFieldBasic(); Dictionary <string, object> dictOutput = gcParams.ToDictionary(); var test = dictOutput.ToQueryString(); Assert.IsInstanceOfType(test, typeof(string), test); Assert.AreEqual(test, multiLineBasicJson); GeocodeService service = new GeocodeService(); GeocodeResult result = service.FindAddressCandidates(gcParams, this.Token); Assert.IsInstanceOfType(result, typeof(GeocodeResult)); Assert.IsNotNull(result.candidates, "Candidates should not be null."); Assert.IsNotNull(result.spatialReference, "Spatial Reference should not be null."); }
/*oblicza trasę na podstawie otrzymanych współrzędnych * jesli waypointów mniej niż dwa informacja * w przeciwnym wypadku zapisz je na mapie */ public void CalculateRoute(Microsoft.Phone.Controls.Maps.Map map, GeocodeService.GeocodeResult[] coordinates, Helper.MapResultReceived croute, TravelMode tm = TravelMode.Driving) { if (coordinates.Length < 2) { MessageBox.Show("Too small number od location: you need startPoint and endpoint at least"); return; } try { MapResponseSendHere = new Helper.MapResultReceived(croute); routedMap = map; RouteService.RouteServiceClient routeService = new RouteService.RouteServiceClient("BasicHttpBinding_IRouteService"); routeService.Endpoint.Binding.ReceiveTimeout = timeout; routeService.Endpoint.Binding.SendTimeout = timeout; routeService.Endpoint.Binding.OpenTimeout = timeout; RouteRequest routeRequest = new RouteRequest(); { routeRequest.Credentials = new Microsoft.Phone.Controls.Maps.Credentials() { ApplicationId = bingMapKey }; routeRequest.Options = new RouteService.RouteOptions() { RoutePathType = RouteService.RoutePathType.Points, Mode = tm }; } routeRequest.Waypoints = new System.Collections.ObjectModel.ObservableCollection<RouteService.Waypoint>(); foreach (GeocodeService.GeocodeResult coord in coordinates) { if (null != coord) { if (coordinates[coordinates.Length - 1] != coord) //jesli to ostatni punkt ustaw: MOBICA routeRequest.Waypoints.Add(GeocodeToWaypoint(coord)); else routeRequest.Waypoints.Add(GeocodeToWaypoint(coord, "MOBICA")); } } routeService.CalculateRouteCompleted += (sender, e) => CalculateRouteCompleted(sender, e); routeService.CalculateRouteAsync(routeRequest, coordinates.Length); } catch (Exception ex) { MessageBox.Show("An exception occurred: " + ex.Message); } }
// This is the Geocode request callback method. private void geocodeService_GeocodeCompleted(object sender, GeocodeService.GeocodeCompletedEventArgs e) { // Retrieve the user state of this response (the ‘waypoint index’) to identify which geocode request // it corresponds to. int waypointIndex = System.Convert.ToInt32(e.UserState); // Retrieve the GeocodeResult for this response and store it in the global variable geocodeResults, using // the waypoint index to position it in the array. geocodeResults[waypointIndex] = e.Result.Results[0]; // Look at each element in the global gecodeResults array to figure out if more geocode responses still // need to be returned. bool doneGeocoding = true; foreach (GeocodeService.GeocodeResult gr in geocodeResults) { if (gr == null) { doneGeocoding = false; } } // If the geocodeResults array is totally filled, then calculate the route. if (doneGeocoding) { //Clear any existing routes ClearRoute(); //Calculate the route CalculateRoute(geocodeResults); } }
private void geocodeService_ReverseGeocodeCompleted(object sender, GeocodeService.ReverseGeocodeCompletedEventArgs e) { try { if (e.Error == null && e.Result.Results.Count() > 0) { GeocodeResult result = e.Result.Results[0]; String formattedAddress = result.Address.FormattedAddress; getPointFromAddress(formattedAddress); } } catch (Exception ) { throw ; } }
private void geocodeService_GeocodeCompleted(object sender, GeocodeService.GeocodeCompletedEventArgs e) { try { if (e.Error == null && e.Result.Results.Count() > 0) { GeocodeResult result = e.Result.Results[0]; addPushPinToLocation(result.Locations[0]); } } catch (Exception) { throw; } }
//otrzymane współrzędne zostaną wysłane na zapisaną wcześniej do słownika funkcję private void GeocodeCompleted(object sender, GeocodeService.GeocodeCompletedEventArgs e) { if (e.Result.Results.Count > 0) { GeocodeResult coordinatesReceived = e.Result.Results[0]; //MessageBox.Show("Latitude: " + coordinatesReceived.Locations[0].Latitude + "\nLongitude: " + coordinatesReceived.Locations[0].Longitude); if (GeocodeResponseSendHere.ContainsKey(System.Convert.ToInt32(e.UserState))) { GeocodeResponseSendHere[System.Convert.ToInt32(e.UserState)](coordinatesReceived); GeocodeResponseSendHere.Remove(System.Convert.ToInt32(e.UserState)); } } else MessageBox.Show("No location found"); }
public async Task <IActionResult> StoreData([Bind("Id,CompanyName,Description,EMail,Website,Activated,CreatedAt,PostCode,City,Address,Country,FederalState,Telephonenumber,Password")] TableStore tableStore, IFormFile logoFile) { var storeId = User.FindFirst(ClaimTypes.NameIdentifier).Value; if (ModelState.IsValid) { //update try { var tbStore = await _context.TblStores.FirstOrDefaultAsync(x => x.Id == tableStore.Id); var logo = CreateImage(logoFile, EnumImageType.Logo); if (!(logo is null)) { var storeImages = _context.TblStores.Where(s => s.Id.ToString() == storeId).Select(s => s.Images).ToArray(); logo.Store = tbStore; if (storeImages[0].Any()) { for (int i = 0; i < storeImages[0].Count(); i++) { if (storeImages[0][i].ImageType == EnumImageType.Logo) { _context.TblImages.Remove(storeImages[0][i]); break; } } } _context.TblImages.Add(logo); } if (tbStore == null) { return(NotFound()); } if (!String.IsNullOrEmpty(tableStore.Telephonenumber)) { string outPhoneNumber; var a = ValidationHelper.ProoveValidPhoneNumber(tableStore.Telephonenumber, out outPhoneNumber); //TODO: Meldung wenn nicht passt tableStore.Telephonenumber = outPhoneNumber; } if (!String.IsNullOrEmpty(tableStore.Website)) { if (!tableStore.Website.StartsWith("http")) { tableStore.Website = $"http://{tableStore.Website}"; } } tbStore.CompanyName = tableStore.CompanyName; tbStore.Description = tableStore.Description; tbStore.EMail = tableStore.EMail; tbStore.Country = tableStore.Country; tbStore.FederalState = tableStore.FederalState; tbStore.PostCode = tableStore.PostCode; tbStore.City = tableStore.City; tbStore.Address = tableStore.Address; tbStore.Website = tableStore.Website; tbStore.Telephonenumber = tableStore.Telephonenumber; var sec = await _context.TblLocations.FirstOrDefaultAsync(a => a.StoreId == tbStore.Id); if (sec == null) { sec = new TableLocation(); sec.StoreId = tbStore.Id; _context.TblLocations.Add(sec); } sec.EMail = tbStore.EMail; sec.Address = tbStore.Address; sec.City = tbStore.City; sec.Country = tbStore.Country; sec.PostCode = tbStore.PostCode; sec.Name = tbStore.CompanyName; sec.Telephonenumber = tbStore.Telephonenumber; try { var res = GeocodeService.ConvertToGPSCoordinates(tableStore.PostCode, tableStore.City, tableStore.Address); tbStore.Longitude = res.Geometry.Location.Longitude; tbStore.Latitude = res.Geometry.Location.Latitude; } catch (Exception e) { } sec.Latitude = tbStore.Latitude; sec.Longitude = tbStore.Longitude; if (!string.IsNullOrWhiteSpace(tableStore.Password)) { tbStore.Password = PasswordHelper.CumputeHash(tableStore.Password); } await _context.SaveChangesAsync(); TempData.Add("message", "Daten erfolgreich gespeichert"); return(RedirectToAction(nameof(StoreData))); } catch (DbUpdateConcurrencyException) { ViewData.Add("message", "Daten konnten nicht gespeichert werden"); return(View(tableStore)); //if (!TableStoreExists(store.Id)) //{ // return NotFound(); //} //else //{ // throw; //} } } return(View(tableStore)); }
private RouteService.Waypoint GeocodeResultToWaypoint(GeocodeService.GeocodeResult result) { RouteService.Waypoint waypoint = new RouteService.Waypoint(); waypoint.Description = result.DisplayName; waypoint.Location = new RouteService.Location(); waypoint.Location.Latitude = result.Locations[0].Latitude; waypoint.Location.Longitude = result.Locations[0].Longitude; return waypoint; }
// This method makes the initial CalculateRoute asynchronous request using the results of the Geocode Service. private void CalculateRoute(GeocodeService.GeocodeResult[] locations) { // Create the service variable and set the callback method using the CalculateRouteCompleted property. RouteServiceClient routeService = new RouteServiceClient("BasicHttpBinding_IRouteService"); routeService.CalculateRouteCompleted += new EventHandler<CalculateRouteCompletedEventArgs>(routeService_CalculateRouteCompleted); // Set the credentials. RouteService.RouteRequest routeRequest = new RouteService.RouteRequest(); routeRequest.Culture = MyMap.Culture; routeRequest.Credentials = new RouteService.Credentials(); routeRequest.Credentials.ApplicationId = ((ApplicationIdCredentialsProvider)MyMap.CredentialsProvider).ApplicationId; // Return the route points so the route can be drawn. routeRequest.Options = new RouteService.RouteOptions(); routeRequest.Options.RoutePathType = RouteService.RoutePathType.Points; // Set the waypoints of the route to be calculated using the Geocode Service results stored in the geocodeResults variable. routeRequest.Waypoints = new System.Collections.ObjectModel.ObservableCollection<RouteService.Waypoint>(); foreach (GeocodeService.GeocodeResult result in locations) { routeRequest.Waypoints.Add(GeocodeResultToWaypoint(result)); } // Make asynchronous call to fetch the data ... pass state object. // Make the CalculateRoute asnychronous request. routeService.CalculateRouteAsync(routeRequest); }
void geocodeClient_GeocodeCompleted(object sender, GeocodeService.GeocodeCompletedEventArgs e) { if (e.Error == null) { if (e.Result.Results.Count > 0) { foreach (var item in e.Result.Results) { //Debug.WriteLine(item.Locations[0].Latitude.ToString()); //Debug.WriteLine(item.Locations[0].Longitude.ToString()); //Debug.WriteLine(item.Address.FormattedAddress.ToString()); GeoItemViewModel geoItem = new GeoItemViewModel(); geoItem.Latitude = item.Locations[0].Latitude.ToString(); geoItem.Longitude = item.Locations[0].Longitude.ToString(); geoItem.AddressLine = item.Address.FormattedAddress.ToString(); this.Items.Add(geoItem); this.IsAddressResult = true; NotifyPropertyChanged("AddressResultVisibility"); } this.IsDataLoaded = true; } else { //Debug.WriteLine("no results"); this.IsAddressResult = false; NotifyPropertyChanged("AddressResultVisibility"); this.IsDataLoaded = false; } } else { //Debug.WriteLine("Geocode Error"); MessageBox.Show("Error in Geocoding Service! Please go back and try again."); } }
public GeocoderHelper() { _geocoderStore = ReadWriteFileHelper.ReadFromXmlFile <GeocoderStore>(Filename); _geocodeService = new GeocodeService(); }