string ResolveAddressSync() { string Location; GeoCoordinateWatcher watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High); watcher.MovementThreshold = 1.0; // set to one meter watcher.TryStart(false, TimeSpan.FromMilliseconds(1000)); CivicAddressResolver resolver = new CivicAddressResolver(); if (watcher.Position.Location.IsUnknown == false) { CivicAddress address = resolver.ResolveAddress(watcher.Position.Location); if (!address.IsUnknown) { Location = $"Country:{address.CountryRegion}, City: {address.City}"; return(_location = Location); } else { Location = "Address unknown."; return(_location = Location); } } else { Location = "Address unknown."; return(_location = Location); } }
public CivicAddress ResolveAddress(GeoCoordinate coordinate) { var signal = new ManualResetEvent(false); var address = new CivicAddress(); Exception error = null; ResolveAddressAsync(coordinate, args => { try { if (args.Error != null) { error = args.Error; return; } address = ParseResult(args); } catch (Exception ex) { error = ex; } finally { signal.Set(); } }); signal.WaitOne(); if (error != null) throw error; return address; }
public static string GetCompleteAddress(CivicAddress address) { if (address == null) { return(""); } List <string> listAddress = new List <string>(); if (!string.IsNullOrEmpty(address.AddressLine1)) { listAddress.Add(address.AddressLine1); } if (!string.IsNullOrEmpty(address.AddressLine2)) { listAddress.Add(address.AddressLine2); } if (!string.IsNullOrEmpty(address.Building)) { listAddress.Add(address.Building); } if (!string.IsNullOrEmpty(address.City)) { listAddress.Add(address.City); } if (!string.IsNullOrEmpty(address.CountryRegion)) { listAddress.Add(address.CountryRegion); } return(string.Join(", ", listAddress)); }
private static void copyObject <T>(T source, T target) { var props = typeof(T).GetProperties(); foreach (var p in props) { if (p.PropertyType == typeof(CivicAddress)) { CivicAddress instance = new CivicAddress(); CivicAddress propertySource = p.GetValue(source) as CivicAddress; copyObject <CivicAddress>(propertySource, instance); p.SetValue(target, instance); } else if (p.PropertyType == typeof(Bank)) { Bank instance = new Bank(); Bank propertySource = p.GetValue(source) as Bank; copyObject <Bank>(propertySource, instance); p.SetValue(target, instance); } else { p.SetValue(target, p.GetValue(source)); } } }
/// <summary> /// Lookup the address of a given location. /// </summary> /// <param name="coordinates">Coordinates to the location to lookup.</param> /// <param name="address">Address to the coordinates passed.</param> /// <returns>If lookup is successful.</returns> public bool TryLookup(GeoCoordinate coordinates, out CivicAddress address) { try { if (GetFromCache(coordinates, out address)) { return(true); } foreach (IAddressResolver civicResolverService in GetCivicResolverServices()) { if (civicResolverService.TryResolveCivicAddress(coordinates, out address)) { _locationCache[coordinates] = address; return(true); } } } catch (Exception ex) { ServiceRegistration.Get <ILogger>().Error("Error while executing reverse geocoding.", ex); throw; } address = null; return(false); }
public void addressResolution(GeoCoordinate watcher) { CivicAddressResolver resolver = new CivicAddressResolver(); CivicAddress address = resolver.ResolveAddress(watcher); TestBlock.Text = address.AddressLine1; }
/* (non-Javadoc) * @see com.jagornet.dhcpv6.option.Decodable#decode(java.nio.ByteBuffer) */ public override void Decode(ByteBuffer buf) { int len = base.DecodeLength(buf); if ((len > 0) && (len <= buf.remaining())) { long eof = buf.position() + len; if (buf.position() < eof) { what = Util.GetUnsignedByte(buf); if (buf.position() < eof) { byte[] country = buf.getBytes(2); countryCode = Encoding.ASCII.GetString(country); while (buf.position() < eof) { CivicAddress civicAddr = new CivicAddress(); civicAddr.type = Util.GetUnsignedByte(buf); short caLen = Util.GetUnsignedByte(buf); if (caLen > 0) { byte[] caVal = buf.getBytes(caLen); civicAddr.value = Encoding.ASCII.GetString(caVal); } AddCivicAddress(civicAddr); } } } } }
//<Snippet2> static void ResolveAddressSync() { GeoCoordinateWatcher watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High); watcher.MovementThreshold = 1.0; // set to one meter watcher.TryStart(false, TimeSpan.FromMilliseconds(1000)); CivicAddressResolver resolver = new CivicAddressResolver(); if (watcher.Position.Location.IsUnknown == false) { CivicAddress address = resolver.ResolveAddress(watcher.Position.Location); if (!address.IsUnknown) { Console.WriteLine("Country: {0}, Zip: {1}", address.CountryRegion, address.PostalCode); } else { Console.WriteLine("Address unknown."); } } }
private bool TryLookupInternal(out CivicAddress address, out GeoCoordinate coordinates) { address = null; coordinates = null; IPAddress ip; return(ExternalIPResolver.GetExternalIPAddress(out ip) && TryLookupInternal(ip, out address, out coordinates)); }
// Overloaded constructor for all parameters. public StoreUser(int id, string Name, CivicAddress Address, string PhoneNumber, DateTime Birthday) { ID = id; name = Name; address = Address; phoneNumber = PhoneNumber; birthday = Birthday; }
//Default constructor. public StoreUser() { ID = -1; name = ""; address = new CivicAddress(); phoneNumber = ""; birthday = new DateTime(); }
public void AddCivicAddress(CivicAddress civicAddress) { if (civicAddressList == null) { civicAddressList = new List <CivicAddress>(); } civicAddressList.Add(civicAddress); }
private bool TryLookupInternal(out CivicAddress address, out GeoCoordinate coordinates) { TraceRoute trace = new TraceRoute(); TraceRouteResponse response; trace.TrySearchForFirstExternalAddress(Dns.GetHostEntry("google.com").AddressList[0], 30, out response); return TryLookupInternal(response.FirstResponseIP, out address, out coordinates); }
public void ResolveLocation(string postalCode, string country) { CurrentAddress = new CivicAddress() { PostalCode = postalCode, CountryRegion = country, }; UpdateCurrentLocation(); }
void UpdateAddressData(CivicAddress address) { // @TODO: Handle state like Cancelled or an error... if (!address.IsUnknown) { InfoText.Text = address.AddressLine1 + "\r\n" + address.AddressLine2 + "\r\n" + address.City; } }
private bool TryLookupInternal(out CivicAddress address, out GeoCoordinate coordinates) { TraceRoute trace = new TraceRoute(); TraceRouteResponse response; trace.TrySearchForFirstExternalAddress(Dns.GetHostEntry("google.com").AddressList[0], 30, out response); return(TryLookupInternal(response.FirstResponseIP, out address, out coordinates)); }
public void NewCaEqualsNewCa() { var ca1 = new CivicAddress(); var ca2 = new CivicAddress(); System.Boolean nullEqual1 = ca1.Equals(ca2); System.Boolean nullEqual2 = ca2.Equals(ca1); Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsTrue(nullEqual1); Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsTrue(nullEqual2); }
private bool GetFromCache(GeoCoordinate coordinates, out CivicAddress address) { foreach (KeyValuePair <GeoCoordinate, CivicAddress> location in _locationCache.Where(info => CalculateDistance(info.Key, coordinates) <= CACHE_MAX_DISANCE_KM)) { address = location.Value; return(true); } address = null; return(false); }
public CivicAddress ToCivicAddress() { CivicAddress address = new CivicAddress(); address.CountryRegion = CountryName; address.StateProvince = RegionName; address.City = City; address.PostalCode = ZipCode.ToString(); return(address); }
/// <summary> /// Constructor /// </summary> /// <param name="address"> /// <see cref="Microsoft.Phone.UserData.ContactAddress">ContactAddress</see> object /// </param> public W3ContactAddress(Microsoft.Phone.UserData.ContactAddress address) { CivicAddress civicAddress = address.PhysicalAddress; Street = civicAddress.AddressLine1; City = civicAddress.City; Region = civicAddress.StateProvince; Country = civicAddress.CountryRegion; PostalCode = civicAddress.PostalCode; Kind = address.Kind.ToString().ToLower(); }
/// <summary> /// Retrieve the Address based on the coordinates given. /// </summary> /// <param name="coordinates">Location to lookup.</param> /// <param name="address">Resultant address of the lookup.</param> /// <returns>If lookup is successful.</returns> public bool TryResolveCivicAddress(GeoCoordinate coordinates, out CivicAddress address) { if (_address != null) { address = _address; return(true); } GeoCoordinate temp; return(TryGPSLookupInternal(out temp, out address)); }
public CivicAddress ToCivicAddress() { CivicAddress result = new CivicAddress(); if (AddressInfo.ContainsKey(KEY_CITY)) result.City = AddressInfo[KEY_CITY]; if (AddressInfo.ContainsKey(KEY_STATE)) result.StateProvince = AddressInfo[KEY_STATE]; if (AddressInfo.ContainsKey(KEY_COUNTRY)) result.CountryRegion = AddressInfo[KEY_COUNTRY]; return result; }
public CivicAddress ToCivicAddress() { CivicAddress address = new CivicAddress { CountryRegion = Country, StateProvince = Region, City = City, PostalCode = Postal }; return(address); }
public void CreateBlankCustomer() { string expectedName = ""; CivicAddress expectedAddress = new CivicAddress(); DateTime expectedBirthday = new DateTime(); Customer customer = new Customer(); Assert.AreEqual(-1, customer.ID); Assert.AreEqual(expectedName, customer.name); Assert.AreEqual(expectedAddress.AddressLine1, customer.address.AddressLine1); Assert.AreEqual(expectedBirthday, customer.birthday); }
/// <summary> /// Lookup the address at the given coordinates. /// </summary> /// <param name="coordinates">Coordinates to lookup.</param> /// <param name="address">Address of the coordinates given.</param> /// <returns>If lookup is successful.</returns> public bool TryResolveCivicAddress(GeoCoordinate coordinates, out CivicAddress address) { var downloader = new Downloader { EnableCompression = true }; GeocoderResponse result = downloader.Download<GeocoderResponse>(BuildUrl(coordinates.Latitude, coordinates.Longitude)); if (result == null) { address = null; return false; } address = result.ToCivicAddress(); return !string.IsNullOrWhiteSpace(address.CountryRegion) || !string.IsNullOrWhiteSpace(address.StateProvince) || !string.IsNullOrWhiteSpace(address.City); }
/// <summary> /// Determine the address of the given coordinates. /// </summary> /// <param name="coordinates">Coordinates to lookup.</param> /// <param name="address">Address corresponding to the coordinates.</param> /// <returns>If lookup is successful.</returns> public bool TryResolveCivicAddress(GeoCoordinate coordinates, out CivicAddress address) { var downloader = new Downloader { EnableCompression = true }; downloader.Headers["Accept"] = "application/json"; // Google enables compressed output only, if a valid User-Agent is sent! downloader.Headers["User-Agent"] = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0"; MapsApiGeocodeResponse results = downloader.Download<MapsApiGeocodeResponse>(BuildUrl(coordinates.Latitude, coordinates.Longitude)); if (results == null || results.Results == null || results.Results.Count == 0) { address = null; return false; } address = results.Results[0].ToCivicAddress(); return true; }
public void CreteCustomerFromKnownData() { int id = 4; string name = "Sally Sue"; CivicAddress address = new CivicAddress("1234 Mock dr.", "", "", "City", "Region", "1", "12345", "Oklahoma"); string phoneNumber = "123-123-1234"; DateTime birthday = new DateTime(1945, 3, 12); Customer customer = new Customer(id, name, address, phoneNumber, birthday); Assert.AreEqual(id, customer.ID); Assert.AreEqual(name, customer.name); Assert.AreEqual(address.AddressLine1, customer.address.AddressLine1); Assert.AreEqual(phoneNumber, customer.phoneNumber); Assert.AreEqual(birthday, customer.birthday); }
private async Task <AsyncResult <Tuple <CivicAddress, GeoCoordinate> > > TryLookupInternal() { // Check if we've already looked up the location. if (_coordinates != null && _address != null) { if (!_coordinates.IsUnknown && !_address.IsUnknown) { return(new AsyncResult <Tuple <CivicAddress, GeoCoordinate> >(true, new Tuple <CivicAddress, GeoCoordinate>(_address, _coordinates))); } } TaskCompletionSource <GeoCoordinate> tcs = new TaskCompletionSource <GeoCoordinate>(); _gps.PositionChanged += (sender, args) => { // Need to stop the GPS ASAP otherwise it might trigger again. _gps.Stop(); if (!tcs.TrySetResult(args.Position.Location)) { _gps.Start(suppressPermissionPrompt: true); } }; try { _gps.Start(suppressPermissionPrompt: true); using (var cts = new CancellationTokenSource(10000)) { _coordinates = await tcs.Task.WaitAsync(cts.Token); CivicAddressResolver resolver = new CivicAddressResolver(); _address = resolver.ResolveAddress(_coordinates); return(new AsyncResult <Tuple <CivicAddress, GeoCoordinate> >(true, new Tuple <CivicAddress, GeoCoordinate>(_address, _coordinates))); } } catch (TaskCanceledException) { return(new AsyncResult <Tuple <CivicAddress, GeoCoordinate> >(false, null)); } finally { _gps.Stop(); } }
private bool TryGPSLookupInternal(out GeoCoordinate coordinates, out CivicAddress address) { // Check if we've already looked up the location. if (_coordinates != null && _address != null) { if (!_coordinates.IsUnknown && !_address.IsUnknown) { coordinates = _coordinates; address = _address; return(true); } } TaskCompletionSource <GeoCoordinate> tcs = new TaskCompletionSource <GeoCoordinate>(); _gps.PositionChanged += (sender, args) => { // Need to stop the GPS ASAP otherwise it might trigger again. _gps.Stop(); if (!tcs.TrySetResult(args.Position.Location)) { _gps.Start(suppressPermissionPrompt: true); } }; _gps.Start(suppressPermissionPrompt: true); if (tcs.Task.Wait(10000)) // 10 seconds. { _coordinates = tcs.Task.Result; CivicAddressResolver resolver = new CivicAddressResolver(); _address = resolver.ResolveAddress(_coordinates); coordinates = _coordinates; address = _address; return(true); } _gps.Stop(); coordinates = null; address = null; return(false); }
/// <summary> /// Lookup the address at the given coordinates. /// </summary> /// <param name="coordinates">Coordinates to lookup.</param> /// <param name="address">Address of the coordinates given.</param> /// <returns>If lookup is successful.</returns> public bool TryResolveCivicAddress(GeoCoordinate coordinates, out CivicAddress address) { var downloader = new Downloader { EnableCompression = true }; GeocoderResponse result = downloader.Download <GeocoderResponse>(BuildUrl(coordinates.Latitude, coordinates.Longitude)); if (result == null) { address = null; return(false); } address = result.ToCivicAddress(); return(!string.IsNullOrWhiteSpace(address.CountryRegion) || !string.IsNullOrWhiteSpace(address.StateProvince) || !string.IsNullOrWhiteSpace(address.City)); }
private bool TryGPSLookupInternal(out GeoCoordinate coordinates, out CivicAddress address) { // Check if we've already looked up the location. if (_coordinates != null && _address != null) { if (!_coordinates.IsUnknown && !_address.IsUnknown) { coordinates = _coordinates; address = _address; return true; } } TaskCompletionSource<GeoCoordinate> tcs = new TaskCompletionSource<GeoCoordinate>(); _gps.PositionChanged += (sender, args) => { // Need to stop the GPS ASAP otherwise it might trigger again. _gps.Stop(); if (!tcs.TrySetResult(args.Position.Location)) _gps.Start(suppressPermissionPrompt: true); }; _gps.Start(suppressPermissionPrompt: true); if (tcs.Task.Wait(10000)) // 10 seconds. { _coordinates = tcs.Task.Result; CivicAddressResolver resolver = new CivicAddressResolver(); _address = resolver.ResolveAddress(_coordinates); coordinates = _coordinates; address = _address; return true; } _gps.Stop(); coordinates = null; address = null; return false; }
/// <summary> /// Lookup the location of the current device. /// </summary> /// <param name="coordinates">Coordinates of the device.</param> /// <param name="address">Address of the device.</param> /// <returns>If lookup is successful.</returns> public bool TryLookup(out GeoCoordinate coordinates, out CivicAddress address) { coordinates = null; address = null; if (!NetworkConnectionTracker.IsNetworkConnected) { return(false); } foreach (ICoordinateResolver coordinateResolverService in GetCoordinateResolverServices()) { try { if (coordinateResolverService.TryResolveCoordinates(out coordinates)) { if (GetFromCache(coordinates, out address)) { return(true); } foreach (IAddressResolver civicResolverService in GetCivicResolverServices()) { try { if (civicResolverService.TryResolveCivicAddress(coordinates, out address)) { _locationCache[coordinates] = address; return(true); } } catch (Exception ex) { ServiceRegistration.Get <ILogger>().Error("Error while executing IAddressResolver {0}.", ex, civicResolverService.GetType().Name); } } } } catch (Exception ex) { ServiceRegistration.Get <ILogger>().Error("Error while executing ICoordinateResolver {0}.", ex, coordinateResolverService.GetType().Name); } } return(false); }
public CivicAddress ToCivicAddress() { CivicAddress result = new CivicAddress(); if (AddressInfo.ContainsKey(KEY_CITY)) { result.City = AddressInfo[KEY_CITY]; } if (AddressInfo.ContainsKey(KEY_STATE)) { result.StateProvince = AddressInfo[KEY_STATE]; } if (AddressInfo.ContainsKey(KEY_COUNTRY)) { result.CountryRegion = AddressInfo[KEY_COUNTRY]; } return(result); }
private bool TryLookupInternal(IPAddress ip, out CivicAddress address, out GeoCoordinate coordinates) { var downloader = new Downloader { EnableCompression = true }; downloader.Headers["Accept"] = "application/json"; downloader.Headers["User-Agent"] = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0"; FreeGeoIPResponse result = downloader.Download<FreeGeoIPResponse>(BuildUrl(ip)); if (result == null) { address = null; coordinates = null; return false; } address = result.ToCivicAddress(); coordinates = result.ToGeoCoordinates(); return true; }
/// <summary> /// Determine the address of the given coordinates. /// </summary> /// <param name="coordinates">Coordinates to lookup.</param> /// <param name="address">Address corresponding to the coordinates.</param> /// <returns>If lookup is successful.</returns> public bool TryResolveCivicAddress(GeoCoordinate coordinates, out CivicAddress address) { var downloader = new Downloader { EnableCompression = true }; downloader.Headers["Accept"] = "application/json"; // Google enables compressed output only, if a valid User-Agent is sent! downloader.Headers["User-Agent"] = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0"; MapsApiGeocodeResponse results = downloader.Download <MapsApiGeocodeResponse>(BuildUrl(coordinates.Latitude, coordinates.Longitude)); if (results == null || results.Results == null || results.Results.Count == 0) { address = null; return(false); } address = results.Results[0].ToCivicAddress(); return(true); }
private static string[] BuildAddressString(CivicAddress civicAddress) { if (civicAddress.IsUnknown) { return(null); } List <string> list = new List <string>(); list.Add(civicAddress.AddressLine1); list.Add(civicAddress.AddressLine2); list.Add(civicAddress.Building); list.Add(civicAddress.City); list.Add(civicAddress.CountryRegion); list.Add(civicAddress.FloorLevel); list.Add(civicAddress.PostalCode); list.Add(civicAddress.StateProvince); return(list.ToArray()); }
/// <summary> /// Resolves an address from a <see cref="T:GeoCoordinate"/> using Bing Maps. /// </summary> /// <param name="geoCoordinate"></param> public static void ResolveLocation(GeoCoordinate geoCoordinate, Action <CivicAddress, Exception> callback) { if (geoCoordinate == null) { throw new ArgumentNullException("geoCoordinate"); } if (callback == null) { throw new ArgumentNullException("callback"); } var client = new RestClient("https://dev.virtualearth.net"); var request = new RestRequest(); request.Resource = "REST/v1/Locations/{latitude},{longitude}?key={key}"; request.AddUrlSegment("latitude", geoCoordinate.Latitude.ToString(CultureInfo.InvariantCulture)); request.AddUrlSegment("longitude", geoCoordinate.Longitude.ToString(CultureInfo.InvariantCulture)); request.AddUrlSegment("key", Resources.BingMapsKey); client.ExecuteAsync <BingLocationResponse>(request, (response) => { var result = response.Data; var civicAddress = new CivicAddress(); if ((result != null) && (result.ResourceSets.Count > 0) && (result.ResourceSets[0].Resources.Count > 0)) { var resources = result.ResourceSets[0].Resources[0]; civicAddress.CountryRegion = resources.Address.CountryRegion; civicAddress.AddressLine1 = resources.Address.AddressLine; civicAddress.PostalCode = resources.Address.PostalCode; } callback(civicAddress, response.ErrorException); }); }
public void CivicAddressOutputTest() { //-- Arrange CivicAddress actual = new CivicAddress(); actual.AddressLine1 = "742 Redwing Park Dr."; actual.City = "Houston"; actual.CountryRegion = "USA"; actual.PostalCode = "77009"; actual.StateProvince = "TX"; //-- Act CivicAddress expected = new CivicAddress("742 Redwing Park Dr.", "", "", "Houston", "USA", "", "92867", "TX"); //-- Assert Assert.AreEqual(expected.City, actual.City); // LESSON: can't compare reference types (objects) directly like you // do with value types. MUST ASSERT EACH FIELD. }
public void ResolveAddressAsync(GeoCoordinate coordinate) { ResolveAddressAsync(coordinate, args => { var error = args.Error; var address = new CivicAddress(); try { if (!args.Cancelled && args.Error == null) { address = ParseResult(args); } } catch (Exception ex) { error = ex; } finally { var handler = ResolveAddressCompleted; if (handler != null) { handler(this, new ResolveAddressCompletedEventArgs(address, error, args.Cancelled, null)); } } }); }
public void AssignProperties() { int id = 4; string name = "Sally Sue"; CivicAddress address = new CivicAddress("1234 Mock dr.", "", "", "City", "Region", "1", "12345", "Oklahoma"); string phoneNumber = "123-123-1234"; DateTime birthday = new DateTime(1945, 3, 12); Customer customer = new Customer(); customer.ID = id; customer.name = name; customer.address = address; customer.birthday = birthday; customer.phoneNumber = phoneNumber; Assert.AreEqual(id, customer.ID); Assert.AreEqual(name, customer.name); Assert.AreEqual(address.AddressLine1, customer.address.AddressLine1); Assert.AreEqual(phoneNumber, customer.phoneNumber); Assert.AreEqual(birthday, customer.birthday); }
private bool TryLookupInternal(IPAddress ip, out CivicAddress address, out GeoCoordinate coordinates) { var downloader = new Downloader { EnableCompression = true }; downloader.Headers["Accept"] = "application/json"; downloader.Headers["User-Agent"] = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0"; FreeGeoIPResponse result = downloader.Download <FreeGeoIPResponse>(BuildUrl(ip)); if (result == null) { address = null; coordinates = null; return(false); } address = result.ToCivicAddress(); coordinates = result.ToGeoCoordinates(); return(true); }
public CivicAddress ToCivicAddress() { CivicAddress result = new CivicAddress(); var city = GetAddressComponent("locality"); if (city != null) { result.City = city.LongName; } var state = GetAddressComponent("administrative_area_level_1"); if (state != null) { result.StateProvince = state.LongName; } var country = GetAddressComponent("country"); if (country != null) { result.CountryRegion = country.LongName; } return(result); }
public static void downloadBanksXML() { XElement bankRoot = XElement.Load(@"https://www.boi.org.il/he/BankingSupervision/BanksAndBranchLocations/Lists/BoiBankBranchesDocs/atm.xml"); XElement localRoot = new XElement(getXName("banks")); foreach (XElement bank in bankRoot.Elements()) { XElement localFileElement = new XElement(getXName("Bank")); localFileElement.Add(getXElement("BankNumber", bank.Element(getXName("קוד_בנק")).Value)); string bankAddress = bank.Element("כתובת_ה-ATM").Value; string city = bank.Element("ישוב").Value; string[] bankAddressSplitted = bankAddress.Replace(city, "").Trim().Split(' '); string houseNumber = ""; string streetName = ""; for (int i = 0; i < bankAddressSplitted.Length; i++) { uint value; if (uint.TryParse(bankAddressSplitted[i], out value)) { houseNumber = bankAddressSplitted[i]; break; } streetName += bankAddressSplitted[i]; } CivicAddress address = new CivicAddress { City = city, StreetName = streetName, HouseNumber = uint.Parse(houseNumber), IsPrivateHouse = true, ApartmentNumber = 0 }; XElement addressElement = serializeValue(address, civicAddressSerilizer); addressElement.Name = getXName("BranchAddress"); localFileElement.Add(addressElement); localFileElement.Add(getXElement("BankName", bank.Element("שם_בנק").Value.Trim(' ', '\n', '\r'))); //TODO fix branches localFileElement.Add(getXElement("BranchNumber", bank.Element("קוד_סניף").Value)); localRoot.Add(localFileElement); } localRoot.Save(filePath(BanksFile)); BanksElement = localRoot; }
/// <summary> /// Resolves an address from a <see cref="T:GeoCoordinate"/> using Bing Maps. /// </summary> /// <param name="geoCoordinate"></param> public static void ResolveLocation(GeoCoordinate geoCoordinate, Action<CivicAddress, Exception> callback) { if (geoCoordinate == null) throw new ArgumentNullException("geoCoordinate"); if (callback == null) throw new ArgumentNullException("callback"); var client = new RestClient("https://dev.virtualearth.net"); var request = new RestRequest(); request.Resource = "REST/v1/Locations/{latitude},{longitude}?key={key}"; request.AddUrlSegment("latitude", geoCoordinate.Latitude.ToString(CultureInfo.InvariantCulture)); request.AddUrlSegment("longitude", geoCoordinate.Longitude.ToString(CultureInfo.InvariantCulture)); request.AddUrlSegment("key", Resources.BingMapsKey); client.ExecuteAsync<BingLocationResponse>(request, (response) => { var result = response.Data; var civicAddress = new CivicAddress(); if ((result != null) && (result.ResourceSets.Count > 0) && (result.ResourceSets[0].Resources.Count > 0)) { var resources = result.ResourceSets[0].Resources[0]; civicAddress.CountryRegion = resources.Address.CountryRegion; civicAddress.AddressLine1 = resources.Address.AddressLine; civicAddress.PostalCode = resources.Address.PostalCode; } callback(civicAddress, response.ErrorException); }); }
/// <summary> /// Determine the address at the specified coordinates. /// </summary> /// <param name="coordinates">Coordinates to lookup.</param> /// <param name="address">Resultant address.</param> /// <returns>If lookup is successful.</returns> public bool TryResolveCivicAddress(GeoCoordinate coordinates, out CivicAddress address) { GeoCoordinate temp; return TryLookupInternal(out address, out temp); }
private static string[] BuildAddressString(CivicAddress civicAddress) { if (civicAddress.IsUnknown) return null; List<string> list = new List<string>(); list.Add(civicAddress.AddressLine1); list.Add(civicAddress.AddressLine2); list.Add(civicAddress.Building); list.Add(civicAddress.City); list.Add(civicAddress.CountryRegion); list.Add(civicAddress.FloorLevel); list.Add(civicAddress.PostalCode); list.Add(civicAddress.StateProvince); return list.ToArray(); }
public CivicAddress ResolveAddress(GeoCoordinate coordinate) { Contract.Requires(coordinate != null); String addressLine1 = null, addressLine2 = null, building = null, city = null; String countryRegion = null; String state = null; city = ResolveCity(coordinate, out state); if (city == null) city = "<unknown>"; double errorThreshold = AllowWideRangeForErrors ? ErrorThresholdForSearching : VeryPreciseErrorThreshold; // @TODO: My data files are a little inconsistent. For Vegas, the building is usually the second option, like loc.Name. // For Microsoft main campus, the building is the point of interest, while the main campus is the name. IList<Location> locs = FindLocations(coordinate, errorThreshold); if (locs.Count > 0) { building = locs[0].Name; if (locs[0].PointOfInterestName != null) { addressLine1 = locs[0].PointOfInterestName; addressLine2 = locs[0].Name; building = locs[0].Name; } else addressLine1 = building; if (locs.Count > 1) { foreach (Location loc in locs) { if (loc.PointOfInterestName != null) { addressLine1 = loc.PointOfInterestName; addressLine2 = loc.Name; if (building == null) building = loc.Name; break; } } } } CivicAddress address = new CivicAddress(addressLine1, addressLine2, building, city, countryRegion, null, null, state); EventHandler<ResolveAddressCompletedEventArgs> handler = ResolveAddressCompleted; if (handler != null) { ResolveAddressCompletedEventArgs args = new ResolveAddressCompletedEventArgs(address, null, false, null); handler(this, args); } return address; }
/// <summary> /// Lookup the location of the current device. /// </summary> /// <param name="coordinates">Coordinates of the device.</param> /// <param name="address">Address of the device.</param> /// <returns>If lookup is successful.</returns> public bool TryLookup(out GeoCoordinate coordinates, out CivicAddress address) { try { if (NetworkConnectionTracker.IsNetworkConnected) foreach (ICoordinateResolver coordinateResolverService in GetCoordinateResolverServices()) if (coordinateResolverService.TryResolveCoordinates(out coordinates)) { if (GetFromCache(coordinates, out address)) return true; foreach (IAddressResolver civicResolverService in GetCivicResolverServices()) if (civicResolverService.TryResolveCivicAddress(coordinates, out address)) { _locationCache[coordinates] = address; return true; } } } catch (Exception ex) { ServiceRegistration.Get<ILogger>().Error("Error while executing reverse geocoding.", ex); } coordinates = null; address = null; return false; }
public void ConvertLocation(GeoCoordinate location) { Debug.WriteLine("ConvertLocation"); // converts a point to an address Debug.WriteLine("ConvertLocation" ); Debug.WriteLine("GeoCoordinate:" + location.ToString()); CivicAddressResolver resolver = new CivicAddressResolver(); CivicAddress d = new CivicAddress(); if (location.IsUnknown == false) { CivicAddress address = resolver.ResolveAddress(location); Debug.WriteLine("CivicAddress:" + address.ToString()); if (!address.IsUnknown) { Debug.WriteLine("Country: {0}, Zip: {1}", address.CountryRegion, address.PostalCode); } else { Debug.WriteLine("Address unknown."); } } }
public CivicAddress ToCivicAddress() { CivicAddress address = new CivicAddress(); address.CountryRegion = CountryName; address.StateProvince = RegionName; address.City = City; address.PostalCode = ZipCode.ToString(); return address; }
public Employee(int id, string Name, CivicAddress Address, string PhoneNumber, DateTime Birthday, ulong permissions, string permission_group) : base(id, Name, Address, PhoneNumber, Birthday) { Permissions = permissions; PermissionGroup = permission_group; }
public CivicAddress ToCivicAddress() { CivicAddress result = new CivicAddress(); var city = GetAddressComponent("locality"); if (city != null) result.City = city.LongName; var state = GetAddressComponent("administrative_area_level_1"); if (state != null) result.StateProvince = state.LongName; var country = GetAddressComponent("country"); if (country != null) result.CountryRegion = country.LongName; return result; }
/// <summary> /// Retrieve the Address based on the coordinates given. /// </summary> /// <param name="coordinates">Location to lookup.</param> /// <param name="address">Resultant address of the lookup.</param> /// <returns>If lookup is successful.</returns> public bool TryResolveCivicAddress(GeoCoordinate coordinates, out CivicAddress address) { if (_address != null) { address = _address; return true; } GeoCoordinate temp; return TryGPSLookupInternal(out temp, out address); }
/// <summary> /// Lookup the address of a given location. /// </summary> /// <param name="coordinates">Coordinates to the location to lookup.</param> /// <param name="address">Address to the coordinates passed.</param> /// <returns>If lookup is successful.</returns> public bool TryLookup(GeoCoordinate coordinates, out CivicAddress address) { try { if (GetFromCache(coordinates, out address)) return true; foreach (IAddressResolver civicResolverService in GetCivicResolverServices()) if (civicResolverService.TryResolveCivicAddress(coordinates, out address)) { _locationCache.Add(coordinates, address); return true; } } catch (Exception ex) { ServiceRegistration.Get<ILogger>().Error("Error while executing reverse geocoding.", ex); throw; } address = null; return false; }
private bool GetFromCache(GeoCoordinate coordinates, out CivicAddress address) { foreach (KeyValuePair<GeoCoordinate, CivicAddress> location in _locationCache.Where(info => CalculateDistance(info.Key, coordinates) <= CACHE_MAX_DISANCE_KM)) { address = location.Value; return true; } address = null; return false; }