Example #1
0
    public IEnumerator ShowWeatherCity3(string a)
    {
        GameObject     input = GameObject.Find("SpringPowerUp");
        weatherpowerup wp    = input.GetComponent <weatherpowerup>();

        a = wp.city3;
        string qrl = "http://api.openweathermap.org/data/2.5/find?q=" + a + "&type=accurate&mode=xml&lang=nl&units=imperial&appid=4f258e4971d0c07f770b8bc4759fb32e";

        using (UnityWebRequest qww = UnityWebRequest.Get(qrl)) {
            yield return(qww.SendWebRequest());

            if (qww.isNetworkError || qww.isHttpError)
            {
                print(qww.error);
            }
            else
            {
                print("Loaded following XML " + qww.downloadHandler.text);
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(qww.downloadHandler.text);
                city   = xmlDoc.SelectSingleNode("cities/list/item/city/@name").InnerText;
                temp   = xmlDoc.SelectSingleNode("cities/list/item/temperature/@value").InnerText;
                humidy = xmlDoc.SelectSingleNode("cities/list/item/humidity /@value").InnerText;
                clouds = xmlDoc.SelectSingleNode("cities/list/item/clouds/@value").InnerText;
                Title  = xmlDoc.SelectSingleNode("cities /list/item/weather/@value").InnerText;
                print("City: " + city);
                print("Temperature: " + temp);
                print("humidity: " + humidy);
                print("Cloud : " + clouds);
                print("Title: " + Title);
                wp.ThirdCity.GetComponentInChildren <Text>().text = city + " " + temp + " F";
                //float t;
                // Debug.Log("this is temp: " + temp);

                /* t= float.Parse(temp);
                 * //Int32.TryParse(temp, out t);
                 * Debug.Log("this is t: " + t);
                 * if(t < 32)
                 * {
                 *  Debug.Log("Wrap to Winter");
                 * SceneManager.LoadScene(7);
                 *
                 * }
                 * else if(t >= 32 && t <= 70) {
                 *  Debug.Log("Wrap to Spring");
                 * SceneManager.LoadScene(1);
                 * }
                 * else if(t >= 90 && t <= 150) {
                 *  Debug.Log("Wrap to Summer");
                 * SceneManager.LoadScene(3);
                 * }
                 * else if(t > 70 && t < 90) {
                 *  Debug.Log("Wrap to Fall");
                 * SceneManager.LoadScene(6);
                 * }
                 */
                Debug.Log("this in weathe function " + a);
            }
        }
    }
Example #2
0
    public IEnumerator ShowWeather()
    {
        string a   = LocalIPAddress();
        string url = "api.ipgeolocation.io/ipgeo?apiKey=63675d7f1aa14c7fbeda269fb00bee57&ip=" + a + "&fields=city";

        //WWW www = new WWW(url);
        using (UnityWebRequest www = UnityWebRequest.Get(url)) {
            yield return(www.SendWebRequest());

            if (www.isNetworkError || www.isHttpError)
            {
                print(www.error);
            }
            else
            {
                print(www.downloadHandler.text);
                ipcity = www.downloadHandler.text;
                string[] arr = ipcity.Split(':');
                ipcity = arr[2];
                ipcity = ipcity.Trim(new Char[] { '\"', '}' });
                print("Loaded following: " + ipcity);
                print(www.downloadHandler.data);
                bruh = ipcity;
            }
        }
        print("BRUH:" + bruh);
        string qrl = "http://api.openweathermap.org/data/2.5/find?q=" + bruh + "&type=accurate&mode=xml&lang=nl&units=imperial&appid=4f258e4971d0c07f770b8bc4759fb32e";

        //WWW qww = new WWW(qrl);
        using (UnityWebRequest qww = UnityWebRequest.Get(qrl)) {
            yield return(qww.SendWebRequest());

            if (qww.isNetworkError || qww.isHttpError)
            {
                print(qww.error);
            }
            else
            {
                GameObject     input = GameObject.Find("SpringPowerUp");
                weatherpowerup w     = input.GetComponent <weatherpowerup>();

                print("Loaded following XML " + qww.downloadHandler.text);
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(qww.downloadHandler.text);
                city   = xmlDoc.SelectSingleNode("cities/list/item/city/@name").InnerText;
                temp   = xmlDoc.SelectSingleNode("cities/list/item/temperature/@value").InnerText;
                humidy = xmlDoc.SelectSingleNode("cities/list/item/humidity /@value").InnerText;
                clouds = xmlDoc.SelectSingleNode("cities/list/item/clouds/@value").InnerText;
                Title  = xmlDoc.SelectSingleNode("cities /list/item/weather/@value").InnerText;
                print("City: " + city);
                print("Temperature: " + temp);
                print("humidity: " + humidy);
                print("Cloud : " + clouds);
                print("Title: " + Title);

                w.currentLocation.GetComponentInChildren <Text>().text = city + " " + temp + " F";

                /*float t;
                 * Debug.Log("this is temp: " + temp);
                 * t= float.Parse(temp);
                 * //Int32.TryParse(temp, out t);
                 * Debug.Log("this is t: " + t);
                 * if(t < 32)
                 * {
                 *     Debug.Log("Wrap to Winter");
                 * SceneManager.LoadScene(7);
                 *
                 * }
                 * else if(t >= 32 && t <= 70) {
                 *     Debug.Log("Wrap to Spring");
                 * SceneManager.LoadScene(1);
                 * }
                 * else if(t >= 90 && t <= 150) {
                 *     Debug.Log("Wrap to Summer");
                 * SceneManager.LoadScene(3);
                 * }
                 * else if(t > 70 && t < 90) {
                 *     Debug.Log("Wrap to Fall");
                 * SceneManager.LoadScene(6);
                 * }
                 */
            }
        }
    }