1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > 根据当前公网IP获取当前城市天气

根据当前公网IP获取当前城市天气

时间:2018-08-09 16:56:55

相关推荐

根据当前公网IP获取当前城市天气

根据不固定公网IP获取当前城市实时天气

获取本机公网IP

根据公网IP查找城市

通过获取城市解析天气

IEnumerator GetIP(){UnityWebRequest wwwWebIp = UnityWebRequest.Get(@"/");yield return wwwWebIp.SendWebRequest();if (wwwWebIp.isNetworkError || wwwWebIp.isHttpError){yield break;}else{// Debug.Log(wwwWebIp.downloadHandler.text);}string urlWeather = "/v3/location/search.json?key=SF0kp6pydMUKGZcEr&q=" + wwwWebIp.downloadHandler.text;//根据IP找城市UnityWebRequest wwwQueryCity = UnityWebRequest.Get(urlWeather);yield return wwwQueryCity.SendWebRequest();if (wwwQueryCity.isNetworkError){yield break;}else{// Debug.Log(wwwQueryCity.downloadHandler.text);}JObject cityData = JsonConvert.DeserializeObject<JObject>(wwwQueryCity.downloadHandler.text);string cityId = cityData["results"][0]["id"].ToString();city = cityData["results"][0]["name"].ToString();string[] arry = cityData["results"][0]["path"].ToString().Split(',');province = arry[2];string urlWeathers = "/v3/weather/now.json?key=SF0kp6pydMUKGZcEr&location=" + cityId + "&language=zh-Hans&unit=c";//根据城市找天气UnityWebRequest wwwWeather = UnityWebRequest.Get(urlWeathers);yield return wwwWeather.SendWebRequest();if (wwwWeather.isNetworkError){yield break;}else{Debug.Log(wwwWeather.downloadHandler.text);}//解析天气try{JObject weatherData = JsonConvert.DeserializeObject<JObject>(wwwWeather.downloadHandler.text);string spriteName = string.Format("Weather/{0}@2x", weatherData["results"][0]["now"]["code"].ToString());//天气文字//Debug.Log(weatherData["results"][0]["now"]["text"].ToString()); //天气//Debug.Log(weatherData["results"][0]["now"]["temperature"].ToString()); //温度}catch (System.Exception ex){Debug.Log(ex.Message);}}

#注意事项

string urlWeather = “/v3/location/search.json?key=SF0kp6pydMUKGZcEr&q=” + wwwWebIp.downloadHandler.text;

当前key值需要注册/ 控制台——产品管理——添加产品——获取公钥或者私钥 当前免费版本

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。