/// <summary> /// Convert os pontos de geolocalição eme endereço /// </summary> /// <param name="latitude"></param> /// <param name="longitude"></param> /// <returns>Lista de endereços </returns> public AddressResult ReverseGeocoder(double latitude, double longitude) { try { var y = new ReverseGeocoder(); var r2 = y.ReverseGeocode(new ReverseGeocodeRequest { Longitude = longitude, Latitude = latitude, BreakdownAddressElements = true, ShowExtraTags = true, ShowAlternativeNames = true, ShowGeoJSON = true }); r2.Wait(); return(r2.Result.Address); } catch (Exception ex) { Console.WriteLine(ex.Message); return(null); } }
public GeocodeResponse ReverseGeoCode(double lat, double longitu) { ReverseGeocoder y = new ReverseGeocoder(); Task <GeocodeResponse> r2 = y.ReverseGeocode(new ReverseGeocodeRequest { Latitude = lat, Longitude = longitu, }); GeocodeResponse resp = r2.Result; //string Countrycode = resp.Address.CountryCode; return(resp); }
/// <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); }
private async Task <GeocodeResponse> LocationToAddressInternal(double latitude, double longitude) { var geocoder = new ReverseGeocoder(); var request = await geocoder.ReverseGeocode(new ReverseGeocodeRequest { Latitude = latitude, Longitude = longitude, BreakdownAddressElements = true }); if (request.PlaceID == 0) { return(null); } return(request); }
public void TestSuccessfulReverseGeocodeBuilding() { var y = new ReverseGeocoder(); var r2 = y.ReverseGeocode(new ReverseGeocodeRequest { Longitude = -77.0365298, Latitude = 38.8976763, BreakdownAddressElements = true, ShowExtraTags = true, ShowAlternativeNames = true, ShowGeoJSON = true }); r2.Wait(); Assert.IsTrue(r2.Result.PlaceID > 0); }
public void TestSuccessfulReverseGeocodeRoad() { var z = new ReverseGeocoder(); var r3 = z.ReverseGeocode(new ReverseGeocodeRequest { Longitude = -58.7051622809683, Latitude = -34.440723129053, BreakdownAddressElements = true, ShowExtraTags = true, ShowAlternativeNames = true, ShowGeoJSON = true }); r3.Wait(); Assert.IsTrue((r3.Result.PlaceID > 0) && (r3.Result.Category == "highway") && (r3.Result.ClassType == "motorway")); }
public static string GetAddress(Coordinates loc) { if (loc != null) { var foo = new Nominatim.API.Models.ReverseGeocodeRequest { Latitude = loc.LatF, Longitude = loc.LonF }; var c = new ReverseGeocoder(); var r = c.ReverseGeocode(foo); var res = r.GetAwaiter().GetResult(); var result = res.Address.Country + ", " + (res.Address.City ?? res.Address.Town) + ", " + res.Address.Road + " " + res.Address.HouseNumber; return(result); } else { return(""); } }
static void Main(string[] args) { var y = new ReverseGeocoder(); var r2 = y.ReverseGeocode(new ReverseGeocodeRequest { Longitude = 34.99799765244287, Latitude = 32.81943571434325, BreakdownAddressElements = true, ShowExtraTags = true, ShowAlternativeNames = true, ShowGeoJSON = true }); r2.Wait(); if ((r2.Result.Address != null)) { Console.WriteLine(r2.Result.Address.City); Console.ReadLine(); } }
private GeocodeResponse LocationToAddressInternal(Location location) { var geocoder = new ReverseGeocoder(); var request = geocoder.ReverseGeocode(new ReverseGeocodeRequest { Longitude = location.Longitude, Latitude = location.Latitude, BreakdownAddressElements = true }); request.Wait(); if (request.Status != System.Threading.Tasks.TaskStatus.RanToCompletion) { return(null); } if (request.Result.PlaceID == 0) { return(null); } return(request.Result); }
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); }
public LocationCoordinateAndDescription AddressLookupAndReverseGeocoder( LocationCoordinate locationCoordinateSearch, float locationAccuracyLatitude, float locationAccuracyLongitude, bool onlyFromCache, bool canReverseGeocoder, LocationDescription metadataLocationDescription, bool forceReloadUsingReverseGeocoder) { if (locationCoordinateSearch == null) { //DEBUG return(null); } #region Only From Cache - Nothing in cache - ** return null ** if (onlyFromCache && !LocationCoordinateAndDescriptionExsistInCache(locationCoordinateSearch)) { return(null); } #endregion if (!forceReloadUsingReverseGeocoder) { #region If exist - ** Return ** location from Cache or Database LocationCoordinateAndDescription locationInDatbaseCoordinateAndDescription = ReadLocationNameFromDatabaseOrCache(locationCoordinateSearch, locationAccuracyLatitude, locationAccuracyLongitude); if (locationInDatbaseCoordinateAndDescription != null) { return(locationInDatbaseCoordinateAndDescription); } #endregion #region If not exist in Database, but Metadata has Location info, save it and ** return it *** if (metadataLocationDescription != null) { locationInDatbaseCoordinateAndDescription = new LocationCoordinateAndDescription( locationCoordinateSearch, metadataLocationDescription); WriteLocationName(locationCoordinateSearch, locationInDatbaseCoordinateAndDescription); return(locationInDatbaseCoordinateAndDescription); } #endregion } else { #region When: Force to read from ReverseGeocode - Delete old data and continue to ReverseGeocode ReadLocationNameFromDatabaseOrCache(locationCoordinateSearch, locationAccuracyLatitude, locationAccuracyLongitude); DeleteLocation(locationCoordinateSearch, locationAccuracyLatitude, locationAccuracyLongitude); #endregion } if (canReverseGeocoder) { #region ReverseGeocoder LocationCoordinateAndDescription locationInDatbaseCoordinateAndDescription; try { var y = new ReverseGeocoder(); var r2 = y.ReverseGeocode(new ReverseGeocodeRequest { Longitude = locationCoordinateSearch.Longitude, Latitude = locationCoordinateSearch.Latitude, BreakdownAddressElements = true, ShowExtraTags = true, ShowAlternativeNames = true, ShowGeoJSON = true, PreferredLanguages = PreferredLanguagesString }); r2.Wait(); if (r2.IsCompleted && !r2.IsFaulted && r2.Result != null && r2.Result.Address != null) { locationInDatbaseCoordinateAndDescription = new LocationCoordinateAndDescription(); locationInDatbaseCoordinateAndDescription.Coordinate.Latitude = locationCoordinateSearch.Latitude; locationInDatbaseCoordinateAndDescription.Coordinate.Longitude = locationCoordinateSearch.Longitude; locationInDatbaseCoordinateAndDescription.Description.City = (r2.Result.Address.City + " " + r2.Result.Address.Town + " " + r2.Result.Address.Village).Trim().Replace(" ", " "); locationInDatbaseCoordinateAndDescription.Description.Country = r2.Result.Address.Country; locationInDatbaseCoordinateAndDescription.Description.Name = (r2.Result.Address.Road + " " + r2.Result.Address.HouseNumber).Trim(); locationInDatbaseCoordinateAndDescription.Description.Region = (r2.Result.Address.State + " " + r2.Result.Address.County + " " + r2.Result.Address.Suburb + " " + r2.Result.Address.District + " " + r2.Result.Address.Hamlet).Trim().Replace(" ", " "); locationInDatbaseCoordinateAndDescription.Description.Name = string.IsNullOrEmpty(locationInDatbaseCoordinateAndDescription.Description.Name) ? null : locationInDatbaseCoordinateAndDescription.Description.Name; locationInDatbaseCoordinateAndDescription.Description.Region = string.IsNullOrEmpty(locationInDatbaseCoordinateAndDescription.Description.Region) ? null : locationInDatbaseCoordinateAndDescription.Description.Region; locationInDatbaseCoordinateAndDescription.Description.City = string.IsNullOrEmpty(locationInDatbaseCoordinateAndDescription.Description.City) ? null : locationInDatbaseCoordinateAndDescription.Description.City; locationInDatbaseCoordinateAndDescription.Description.Country = string.IsNullOrEmpty(locationInDatbaseCoordinateAndDescription.Description.Country) ? null : locationInDatbaseCoordinateAndDescription.Description.Country; WriteLocationName(locationCoordinateSearch, locationInDatbaseCoordinateAndDescription); return(locationInDatbaseCoordinateAndDescription); } else { return(null); } } catch (Exception ex) { Logger.Error(ex, "AddressLookup"); } #endregion } return(null); }