Client Documentation

Updated December 12, 2005

Calling the Member service with PHP and the Pear library

Geocoder.us user Rob Hunter found code from The Atlanta PHP user's group to call the free geocoder service. He added a call to the setCredentials method and created an example of using the member service from PHP with the PEAR (PHP Extension and Application Repository).

Read The original post by Ben Ramsey that discusses installing Pear, and then look at Rob's additional setCredentials line. Also see these notes on the PEAR XML-RPC interface

require_once('XML/RPC.php');
$address = '1600 Pennsylvania Av, Washington, DC 20502';
$params = array(new XML_RPC_Value($address, 'string'));
$message = new XML_RPC_Message('geocode', $params);
$client = new XML_RPC_Client('/member/service/xmlrpc', '
geocoder.us');
$client->setCredentials('myusername','mypassword');
$response = $client->send($message);

if (!$response) {
    echo 'Communication error: ' . $client->errstr;
    exit;
}
if (!$response->faultCode()) {
    $value = $response->value();
    $address_data = XML_RPC_decode($value);
    print_r($address_data);
} else {
    echo 'Fault Code: ' . $response->faultCode() . "\n";
    echo 'Fault Reason: ' . $response->faultString() . "\n";
}