geoAPIKey)) { $add .= '&key=' . urlencode($config->geoAPIKey); } $query = 'https://' . self::$_server . self::$_uri . $add; require_once 'HTTP/Request.php'; $request = new HTTP_Request($query); $request->sendRequest(); $string = $request->getResponseBody(); libxml_use_internal_errors(TRUE); $xml = @simplexml_load_string($string); CRM_Utils_Hook::geocoderFormat('Google', $values, $xml); if ($xml === FALSE) { // account blocked maybe? CRM_Core_Error::debug_var('Geocoding failed. Message from Google:', $string); return FALSE; } if (isset($xml->status)) { if ($xml->status == 'OK' && is_a($xml->result->geometry->location, 'SimpleXMLElement' ) ) { $ret = $xml->result->geometry->location->children(); if ($ret->lat && $ret->lng) { $values['geo_code_1'] = (float) $ret->lat; $values['geo_code_2'] = (float) $ret->lng; return TRUE; } } elseif ($xml->status == 'ZERO_RESULTS') { // reset the geo code values if we did not get any good values $values['geo_code_1'] = $values['geo_code_2'] = 'null'; return FALSE; } else { CRM_Core_Error::debug_var("Geocoding failed. Message from Google: ({$xml->status})", (string ) $xml->error_message); $values['geo_code_1'] = $values['geo_code_2'] = 'null'; $values['geo_code_error'] = $xml->status; return FALSE; } } } }