【问题标题】:Google Weather API and Using Custom imageGoogle Weather API 和使用自定义图像
【发布时间】:2023-03-31 19:19:01
【问题描述】:

我正在使用 Google 天气 API 和 PHP 获取条件:

http://www.google.com/ig/api?weather=New%20York

有什么办法可以改变:

<icon data="/ig/images/weather/partly_cloudy.gif"/>

自定义图像?

【问题讨论】:

标签: php api weather weather-api google-weather-api


【解决方案1】:

由于&lt;icon data="/ig/images/weather/partly_cloudy.gif"/&gt; 由 API 返回(顺便说一句,这不是官方 API)。您可以在 PHP 中使用 if 语句来“替换”图像。

if($theAPIResponse->icon->attributes()->data == '/ig/images/weather/partly_cloudy.gif') {
       // Override the nodes data attribute with your custom image
       $theAPIResponse->icon->attributes()->data = '/path/to/your/custom_image.gif';
}

【讨论】:

    【解决方案2】:

    最简单的方法是使用str_replace("google_path","your_path")

    【讨论】:

    • 嗨!如果你想表明某事是代码,你应该用反引号 (`your code`) 将它括起来,或者,如果它是一大块代码,则缩进四个空格。这样你的帖子就会更容易阅读。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多