function weather_google_conditions($lat, $lon)
{
    $enc_lat = geo_utils_prepare_coordinate($lat);
    $enc_lon = geo_utils_prepare_coordinate($lon);
    $query = array('weather' => ",,,{$enc_lat},{$enc_lon}");
    $url = $GLOBALS['weather_google_endpoint'] . "?" . http_build_query($query);
    $rsp = http_get($url);
    if (!$rsp['ok']) {
        return $rsp;
    }
    libxml_use_internal_errors(true);
    $doc = new DOMDocument();
    $doc->loadXML($rsp['body']);
    $xpath = new DOMXpath($doc);
    $cond = $xpath->query("*/current_conditions");
    $current = array();
    foreach ($cond as $c) {
        foreach ($c->childNodes as $node) {
            $k = $node->nodeName;
            $v = $node->getAttribute("data");
            if ($k == 'icon') {
                continue;
            }
            $current[$k] = $v;
        }
        break;
    }
    if (!count($current)) {
        return not_okay("failed to parse conditions");
    }
    $rsp = array('latitude' => $lat, 'longitude' => $lon, 'timestamp' => time(), 'source' => 'google', 'conditions' => $current);
    return okay($rsp);
}
function dots_derive_location_data($data)
{
    $derived = array('ok' => 1);
    $rsp = array('ok' => 0);
    #
    if (is_numeric($data['latitude']) && is_numeric($data['longitude'])) {
        # pass
    } else {
        if (isset($data['geohash'])) {
            $rsp = dots_derive_location_from_geohash($data);
            if (!isset($rsp['error'])) {
                $rsp['error'] = 'failed to convert geohash into a latitude and longitude';
            }
        } else {
        }
    }
    #
    if ($rsp['ok']) {
        #
        # See this? We're not checking to see $derived[$key]
        # is already set...
        #
        foreach ($rsp['keys'] as $key => $from) {
            $derived[$key] = $from;
        }
    } else {
        $derived['ok'] = 0;
        $derived['error'] = $rsp['error'];
    }
    #
    # prepare the latitude and longitude create a geohash
    # unless we've already got one
    #
    if (is_numeric($data['latitude']) && is_numeric($data['longitude'])) {
        $collapse = 0;
        # do not int-ify the coords
        $data['latitude'] = geo_utils_prepare_coordinate($data['latitude'], $collapse);
        $data['longitude'] = geo_utils_prepare_coordinate($data['longitude'], $collapse);
        if (!isset($data['geohash'])) {
            $data['geohash'] = geo_geohash_encode($data['latitude'], $data['longitude']);
            $derived_map = dots_derive_derived_from_map('string keys');
            $derived['ok'] = 1;
            $derived['geohash'] = $derived_map['dotspotting'];
        }
    }
    #
    # By default, 'location' is a free-form string assigned
    # by the user. If we don't already have and we have what
    # looks to be a valid WOE ID (and eventually others) then
    # automagically assign the 'location' column using the
    # SERVICE + ":" + UID syntax and then flag 'location' as
    # being a derived key (in this derived from $derived_from
    # which is sussed out above).
    #
    if (!$data['location'] && $data['yahoo:woeid']) {
        $derived_map = dots_derive_derived_from_map('string keys');
        $data['location'] = "woeid:{$data['yahoo:woeid']}";
        $derived['location'] = $derived_map['dotspotting'];
    }
    return array($data, $derived);
}