Esempio n. 1
0
 public void GetSuggestions_орехов()
 {
     GeoSuggestionRepository target = new GeoSuggestionRepository();
     var act = target.GetOne("россия, москва, орехов");
     var actual = act.suggestions;
     Assert.AreNotEqual(null, act);
     Assert.AreNotEqual(0, actual.Count());
     Assert.AreNotEqual(null, actual.First().id);
     Assert.AreNotEqual(null, actual.First().refer);
     Assert.AreNotEqual(null, actual.First().descr);
 }
Esempio n. 2
0
        public IEnumerable<Doc> GetAllBySuggestion(MongoCollection<Doc> Collection, string Term, out FoundBy FoundBy)
        {
            FoundBy = null;
            var geoSug = new GeoSuggestionRepository();
            var sug = geoSug.GetOne(Term).suggestions.FirstOrDefault();

            if (sug != null)
            {
                System.Net.WebClient client = new System.Net.WebClient();

                client.QueryString.Add("geocode", sug.descr);
                client.QueryString.Add("format", "xml");
                client.QueryString.Add("key", ConfigurationManager.AppSettings["YMapAPIKey"]);

                System.IO.Stream data = client.OpenRead("http://geocode-maps.yandex.ru/1.x");

                System.IO.StreamReader reader = new System.IO.StreamReader(data);
                string str = reader.ReadToEnd();

                data.Close();
                reader.Close();

                XDocument xdoc = XDocument.Parse(str);

                var geoNode = xdoc.Root.Descendants().First(p=>p.Name == XName.Get("pos", "http://www.opengis.net/gml"));

                var geo = geoNode.Value.Split(' ');
                double lat = double.Parse(geo[0], CultureInfo.InvariantCulture);
                double lng = double.Parse(geo[1], CultureInfo.InvariantCulture);

                FoundBy = new FoundBy { term = Term, found = new Line { addr = sug.descr, matches = sug.matches }, point = new GeoPoint { lat = lat, lon = lng } };

                return Collection.Find(Query.Near("station.geo", lat, lng)).Take(6).ToArray();
            }

            return new Doc[0];
        }