save responses from the vasttrafik api in this format, it will make calls to trip service easier
Пример #1
0
        //public Dictionary<string, string> GetNearest(float lat, float lon)
        public List<Location> GetNearest(float lat, float lon)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(HttpContext.Current.ApplicationInstance.Server.MapPath("~/App_Data") + "/bilpooler.xml");

            //XmlNodeList nodeList;
            XmlNode root = doc.DocumentElement;

            double maxDistance = 0.0f;

            string name = "";

            var loc = new Location();

            foreach(XmlNode pool in root.ChildNodes)
            {
                var poolList = pool.Cast<XmlNode>().ToList();
                var poolName = poolList.Where(x => x.Name == "name").Single().InnerText;
                var poolLat = Convert.ToDouble(poolList.Where(x => x.Name == "lat").Single().Value);
                var poolLon = Convert.ToDouble(poolList.Where(x => x.Name == "lon").Single().Value);

                loc.Lat = poolLat.ToString();
                loc.Long = poolLon.ToString();

                double R = 6371;

                double dLat = (Math.PI / 180) * (poolLat - lat);
                double dLon =  (Math.PI / 180) * (poolLon - lon);

                double a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) + Math.Cos( (Math.PI / 180) * (poolLat)) *Math.Cos( (Math.PI / 180) * (lat)) * Math.Sin(dLon / 2) * Math.Sin(dLon / 2);
                double c = 2 * Math.Asin(Math.Min(1, Math.Sqrt(a)));
                double d = Math.Abs(R * c);

                if (d > maxDistance) {
                    maxDistance = d;
                    name = poolName;
                }
            }

            /*Dictionary<string,string> dict = new Dictionary<string,string>();

            dict.Add("distance", maxDistance.ToString());
            dict.Add("name", name);*/

            loc.Name = name;
            loc.Distance = maxDistance.ToString();

            var list = new List<Location>();
            list.Add(loc);

            return list;
        }
Пример #2
0
        /// <summary>
        /// call function GetGBGLocationToCoord in this class to get identifier and coordinates
        /// gives function a static time for the time being, reconsider changing
        /// </summary>
        /// <param name="url"></param>
        /// <param name="key"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <returns></returns>
        public string GetGBGTrip(string url, string key, Location from, Location to)
        {
            var newUrl = string.Format(url
                , key
                , DateTime.Now.AddDays(1).ToShortDateString()
                , "10:30"
                , from.Identifier
                , from.Lat
                , from.Long
                , to.Identifier
                , to.Lat
                , to.Long

                );
            var res = Helper.CreateHttpGet(newUrl, Helper.ContentType.Json);
            return "";
        }