Google Weather API and Using Custom image
-
11-10-2019 - |
Question
I am using Google weather API and PHP for fetch conditions:
http://www.google.com/ig/api?weather=New%20York
Is there any way for change:
<icon data="/ig/images/weather/partly_cloudy.gif"/>
to custom image?
Solution
As <icon data="/ig/images/weather/partly_cloudy.gif"/>
is returned by the API (which is not an official API btw.) you could use an if statement in PHP to "replace" the image.
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';
}
OTHER TIPS
The simplest way is using str_replace("google_path","your_path")
.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow