Пример #1
0
        //Created this method below to call for TrailsDetail -Sammyboy <3
        public static Trails GetTrailById(int Id)
        {
            HttpWebRequest  request  = WebRequest.CreateHttp($"https://www.hikingproject.com/data/get-trails-by-id?ids={Id}&key={Secret.APIkey2}");
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            StreamReader    rd       = new StreamReader(response.GetResponseStream());
            string          APItext  = rd.ReadToEnd();
            JToken          t        = JToken.Parse(APItext);

            //sorry, I understand this line is weird. Even though this is a diferent API URL, it still returns a list with one object in it.
            //I have to grab the first object of that list to get the Trails model to convert the properties propperly
            List <JToken> x       = t["trails"].ToList();
            Trails        myTrail = new Trails(x[0]);

            return(myTrail);
        }
Пример #2
0
        public static List <Trails> GetResults(string location)
        {
            // this method runs the Hiking API and returns a list of Trails
            LatLng          l        = GetLatLng(location);
            HttpWebRequest  request  = WebRequest.CreateHttp($"https://www.hikingproject.com/data/get-trails?lat={l.Lat}&lon={l.Lng}&maxDistance=200&maxResult=100&key={Secret.APIkey2}");
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            StreamReader    rd       = new StreamReader(response.GetResponseStream());
            string          APItext  = rd.ReadToEnd();
            JToken          t        = JToken.Parse(APItext);

            List <Trails> Result = new List <Trails>();
            List <JToken> x      = t["trails"].ToList();

            foreach (JToken y in x)
            {
                Trails z = new Trails(y);
                Result.Add(z);
            }
            return(Result);
        }