sendRequest(); $string = $request->getResponseBody(); libxml_use_internal_errors(TRUE); $xml = @simplexml_load_string($string); 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 == 'OVER_QUERY_LIMIT') { CRM_Core_Error::fatal('Geocoding failed. Message from Google: ' . $xml->status); } } // reset the geo code values if we did not get any good values $values['geo_code_1'] = $values['geo_code_2'] = 'null'; return FALSE; } }