使用使用Unity 3D开发的Android App中的Open Weather Map API

问题描述 投票:0回答:1

我正在使用Unity 3D开发VR应用程序。它使用开放式天气地图API来访问城市的当前天气。在Windows机器上运行时,该代码在Unity中工作正常。但是在将其开发为Android应用并安装到手机中之后,它无法访问天气信息。

IEnumerator GetWeather(){

    WWW request = new WWW("http://api.openweathermap.org/data/2.5/weather?q="+location+"&APPID=e3a642cec13d52496490dfa8e9ba11d3");
   // WWW request = new WWW("http://api.openweathermap.org/data/2.5/weather?q=Anuradhapura,Sri Lanka&APPID=e3a642cec13d52496490dfa8e9ba11d3");
    yield return request;

    if (request.error == null)
    {
        Processjson(request.text);
    }
    else
    {
        Debug.Log(request.error);
    }
}

[谁能告诉我如何通过手机访问https://openweathermap.org/提供的天气信息?预先感谢。

android unity3d virtual-reality openweathermap
1个回答
0
投票

我曾经部署过开放式天气API,并且遇到了同样的问题。您需要允许互联网访问您的Android版本。为此,请转到播放器设置-> Android设置->配置->互联网访问->需要。那应该允许您发出WWW请求并访问API。

© www.soinside.com 2019 - 2024. All rights reserved.