Weather in Toronto
xpath("/xml_api_reply/weather/current_conditions"); $forecast = $xml->xpath("/xml_api_reply/weather/forecast_conditions"); $weather = array(); //Get latitude and longitude by city and sunrise $now = time(); $location = str_replace(" ", "+", $location); $region = 'united+states'; $json = file_get_contents("http://maps.google.com/maps/api/geocode/json?address=$location&sensor=false®ion=$region"); $json = json_decode($json); $lat = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lat'}; $long = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lng'}; $sunrise = date_sunrise($now, SUNFUNCS_RET_TIMESTAMP, $lat, $long, 90.583333, 0); $sunset = date_sunset($now, SUNFUNCS_RET_TIMESTAMP, $lat, $long, 90.583333, 0); if (($now > $sunrise) && ($now < $sunset)){ //day $weather['time'] = 'day'; }else{ //night $weather['time'] = 'night'; }; // do a basic error check to see if we can get the current weather condition for the given location // if no return an error. if(!$current[0]->condition['data']){ $error = "Couldn't determine this location"; $weather['error'] = $error; } $weather['current_tempature'] = $current[0]->temp_f['data']; $weather['weather'] = strtolower($current[0]->condition['data']); return $weather; } ?>