コード例 #1
0
        // GET: Friends
        public ActionResult Index(string DistanceSearch, string FromWhere, string FromWhereCity)
        {
            GoogleMapsAPI maps = GoogleMapsAPI.getInstance();

            // retrieve the current Client's IP
            string clientIp = getUsersIP();

            // use IpApi to retrieve the client's location
            // or use search city
            string lat = null, lng = null;

            if (!String.IsNullOrEmpty(FromWhere) && FromWhere == "other" && !String.IsNullOrEmpty(FromWhereCity))
            {
                string[] location = maps.getAddressInfoByStreet(FromWhereCity);
                if (location != null)
                {
                    lat = location[0];
                    lng = location[1];
                }
            }
            if (String.IsNullOrEmpty(lat) || String.IsNullOrEmpty(lng))
            {
                string location = new WebClient().DownloadString(String.Format("https://ipapi.co/{0}/latlong/", clientIp));
                lat = location.Substring(0, location.IndexOf(",")).Trim();
                lng = location.Substring(lat.Length + 1).Trim();
            }


            // check distance from search
            double dist = 10000;

            if (!String.IsNullOrEmpty(DistanceSearch))
            {
                Double.TryParse(DistanceSearch, out dist);
            }

            //set up for query call
            var pLat  = new SqlParameter("p_lat", lat);
            var pLng  = new SqlParameter("p_lng", lng);
            var pDist = new SqlParameter("p_dist", dist);

            // call the procedure
            var friendList = db.Database.SqlQuery <FriendWithDistanceViewModel>("exec geodist @p_lat, @p_lng, @p_dist", pLat, pLng, pDist);

            // setup info for display
            string address = maps.getAddressInfoByLocation(lat, lng);

            ViewBag.IntellisenseScript = GoogleMapsAPI.getIntellisenseScriptURL();

            FriendListViewModel viewModel = new FriendListViewModel()
            {
                friendList = friendList,
                clientIp   = clientIp,
                lat        = lat,
                lng        = lng,
                location   = address
            };

            return(View(viewModel));
        }
コード例 #2
0
        // GET: Friends/Add
        public ActionResult Add(int?message)
        {
            FriendAddViewModel viewModel = new FriendAddViewModel();

            ViewBag.IntellisenseScript = GoogleMapsAPI.getIntellisenseScriptURL();

            if (message != null)
            {
                // safeguard range
                int index = message >= messages.Length || message < 0 ? messages.Length - 1 : (int)message;
                viewModel.message = messages[index];
            }

            return(View(viewModel));
        }