//Este método obtiene el Lugar más cercano a las Coordenadas enviadas. //Como no se especifica radio retorna un solo lugar public GeonameNode GeoNames_FindNearbyPlaceName(string Latitud, string Longitud) { List <GeonameNode> gnodes = new List <GeonameNode>(); CultureInfo culture; culture = CultureInfo.InvariantCulture; using (var geoNames = new GeoNamesClient()) { var finder = new NearbyPlaceNameFinder { Latitude = Convert.ToDouble(Latitud, culture), Longitude = Convert.ToDouble(Longitud, culture), UserName = UserName, }; var resultados = geoNames.FindNearbyPlaceName(finder); if (resultados != null) { foreach (Toponym res in resultados) { gnodes.Add(parseToponymToGeonameNode(res)); } } } if (gnodes == null) { return(null); } else { return(gnodes[0]); } }
public static void SetGeoNameId(ProductView product, SelectedHotelsEntities db, Hotel hotel, log4net.ILog log) { var placeName = product.Country; if (!String.IsNullOrEmpty(product.County)) { placeName = product.County; } if (!String.IsNullOrEmpty(product.City)) { placeName = product.City; } var geoNames = db.GeoNames.Where(gn => gn.Name.ToLower() == placeName.ToLower()) .OrderByDescending(gn => gn.Population) .ThenByDescending(gn => gn.ModificationDate); if (geoNames.Any()) { var geoName = geoNames.FirstOrDefault(); if (geoName != null) { hotel.GeoNameId = geoName.Id; } } if (hotel.GeoNameId == null && hotel.Location != null && hotel.Location.Latitude.HasValue && hotel.Location.Longitude.HasValue) { using (var geoNamesClient = new GeoNamesClient()) { var finder = new NearbyPlaceNameFinder { Latitude = hotel.Location.Latitude.Value, Longitude = hotel.Location.Longitude.Value, UserName = Settings.Default.GeoNamesUserName }; try { var results = geoNamesClient.FindNearbyPlaceName(finder); if (results != null && results.Any(r => r.FeatureClassName == "P")) { var toponym = results.First(r => r.FeatureClassName == "P"); hotel.GeoNameId = toponym.GeoNameId; } } catch (Exception ex) { log.Error("Error error logging", ex); if (ex.InnerException != null) { log.Error("Error error logging", ex.InnerException); } } } } }
//Este método obtiene el Lugar más cercano a las Coordenadas enviadas. //Adicionando la jerarquía de lugares geográficos public List <GeonameNode> GeoNames_ExtendedFindNearby(string Latitud, string Longitud) { List <GeonameNode> gnodes = new List <GeonameNode>(); using (var geoNames = new GeoNamesClient()) { var finder = new NearbyPlaceNameFinder { Latitude = Convert.ToDouble(Latitud, culture), Longitude = Convert.ToDouble(Longitud, culture), UserName = UserName, }; var resultados = geoNames.FindNearbyPlaceName(finder); //var resultados = geoNames.FindNearbyPlaceName(finder); if (resultados != null) { foreach (Toponym res in resultados) { gnodes.Add(parseToponymToGeonameNode(res)); } } if (gnodes.Count > 0) { gnodes = GeoNames_Hierarchy(Convert.ToInt32((gnodes[0].geonameId), culture)); } else { return(null); } } if (gnodes == null) { return(null); } else { return(gnodes); } }