diff --git a/CRM/Utils/Geocode/GeocoderCa.php b/CRM/Utils/Geocode/GeocoderCa.php index c1cabba..1360684 100644 --- a/CRM/Utils/Geocode/GeocoderCa.php +++ b/CRM/Utils/Geocode/GeocoderCa.php @@ -94,7 +94,8 @@ public static function format(&$values, $stateName = FALSE) { $values['geo_code_error'] = $coord['geo_code_error']; } - CRM_Utils_Hook::geocoderFormat('GeocoderCa', $values, $coord['request_xml']); + $geoCoder = array_pop(explode('_', __CLASS__)); + CRM_Utils_Hook::geocoderFormat($geoCoder, $values, $coord['request_xml']); return isset($coord['geo_code_1'], $coord['geo_code_2']); } diff --git a/CRM/Utils/Geocode/GeocoderXyz.php b/CRM/Utils/Geocode/GeocoderXyz.php new file mode 100644 index 0000000..46da6d7 --- /dev/null +++ b/CRM/Utils/Geocode/GeocoderXyz.php @@ -0,0 +1,71 @@ +geoAPIKey)) { + $add .= '&geoit=XML&auth=' . urlencode($config->geoAPIKey); + } + + $query = 'https://' . self::$_server . '?' . $add; + $client = new GuzzleHttp\Client(); + $request = $client->request('GET', $query, ['timeout' => \Civi::settings()->get('http_timeout')]); + $string = $request->getBody(); + + libxml_use_internal_errors(TRUE); + $xml = @simplexml_load_string($string); + $coords['request_xml'] = $xml; + if (isset($xml->error)) { + $string = sprintf('Error %s: %s', $xml->error->code, $xml->error->description); + CRM_Core_Error::debug_var('Geocoding failed. Message from Geocoder.xyz:', $string); + $coords['geo_code_error'] = $string; + } + if (isset($xml->latt) && isset($xml->longt)) { + $coords['geo_code_1'] = (float) $xml->latt; + $coords['geo_code_2'] = (float) $xml->longt; + } + + return $coords; + } + +}