【问题标题】:Using Open Weather Map API in Android App developed using Unity 3D在使用 Unity 3D 开发的 Android App 中使用 Open Weather Map API
【发布时间】:2019-10-12 16:31:46
【问题描述】:

我正在使用 Unity 3D 开发 VR 应用程序。它使用open weather map API 来访问一个城市的当前天气。该代码在 Windows 机器上运行时在 Unity 中运行良好。但开发成安卓应用安装到手机后,却无法获取天气信息。

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】:

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

【讨论】:

  • 感谢您的精彩解释。但是,不幸的是,在配置菜单中禁用了 Internet 访问 -> 要求。如何启用它?
猜你喜欢
  • 1970-01-01
  • 2017-10-18
  • 2019-06-01
  • 1970-01-01
  • 2016-11-04
  • 1970-01-01
  • 2019-04-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多