コード例 #1
0
        public List <Teacher> SearchInRadius(List <Teacher> teachers, MapSearchViewModel model, string distance)
        {
            List <Teacher> searchList = teachers.ToList();

            foreach (var t in searchList)
            {
                double lat             = System.Math.Pow(System.Convert.ToSingle(t.GeoLocation.Latitude) - System.Convert.ToSingle(model.MapCenter.Latitude), 2);
                double lng             = System.Math.Pow(System.Convert.ToSingle(t.GeoLocation.Longitude) - System.Convert.ToSingle(model.MapCenter.Longitude), 2);
                double teacherDistance = System.Math.Sqrt(lat + lng) % 33;
                if ((teacherDistance) * 100 > System.Convert.ToSingle(distance))
                {
                    teachers.Remove(t);
                }
            }
            return(teachers);
        }
コード例 #2
0
        //
        // GET: /Map/city/streetName/streetNum/distance/category/
        public ActionResult Map(string city, string streetName, string streetNum, string distance, string category)
        {
            //create and set model
            var model = new MapSearchViewModel();

            //get user location
            string adr = city + "," + streetName + " " + streetNum;

            GeoLocation userGeo = null;

            if (!string.IsNullOrEmpty(city))
            {
                userGeo = GetLongitudeAndLatitude(adr);
            }
            // user location resolved set map settings
            if (userGeo != null)
            {
                model.MapCenter = userGeo;
                model.MapZoom   = 12;
            }
            else
            {
                model.MapCenter = GetLongitudeAndLatitude("");
                model.MapZoom   = 8;
            }

            string searchFor = !string.IsNullOrEmpty(category) ? " ב" + category : string.Empty;

            searchFor       = !string.IsNullOrEmpty(city) ? searchFor + " באזור " + city : searchFor;
            model.SearchFor = searchFor;

            List <Teacher> teachers;

            // search for teachers
            if (!string.IsNullOrEmpty(city) && !string.IsNullOrEmpty(category))
            {
                teachers = Db.Teachers.Where(t => t.isActive && t.City.Contains(city) && t.SubjectsToTeach.FirstOrDefault(s => s.Name.Contains(category)) != null).ToList();
            }
            else if (!string.IsNullOrEmpty(city))
            {
                teachers = Db.Teachers.Where(t => t.City.Contains(city)).ToList();
            }
            else if (!string.IsNullOrEmpty(category))
            {
                teachers = Db.Teachers.Where(t => t.isActive && t.SubjectsToTeach.FirstOrDefault(s => s.Name.Contains(category)) != null).ToList();
            }
            else
            {
                teachers = new List <Teacher>();
            }

            // check if geo exist and get if not
            foreach (var t in teachers)
            {
                if (!t.GeoLocation.isExist())
                {
                    // get geo by address
                    var geo = GetLongitudeAndLatitude(t.GetAddressForMap());
                    t.UpdateGeoLocation(geo);
                    Db.SaveChanges();
                }
            }

            // data
            if (!string.IsNullOrEmpty(distance))
            {
                model.Teachers = SearchInRadius(teachers, model, distance);
            }
            else
            {
                model.Teachers = teachers;
            }
            model.ResultCount = model.Teachers.Count;
            // pass model to view
            return(View(model));
        }
コード例 #3
0
 private List <Teacher> radius(List <Teacher> teachers, MapSearchViewModel model, string distance)
 {
     return(Controller.SearchInRadius(teachers, model, distance));
 }