public function testResponseClass()
 {
     $this->communicator->seed($this->service->generateUrl(self::ADDR_JWT_OFFICE, 'json'), self::RESPONSE_JWT_OFFICE);
     $this->service->setResponseClass('ResponseSubclassValid');
     $response = $this->service->geocode(self::ADDR_JWT_OFFICE);
     $this->assertType('GoogleGeocodeResponseV3', $response, 'Was not a GoogleGeocodeResponseV3');
     try {
         $this->service->setResponseClass('ResponseSubclassInvalid');
         $response = $this->service->geocode(self::ADDR_JWT_OFFICE);
         $this->assertType('GoogleGeocodeResponseV3', $response, 'Was not a GoogleGeocodeResponseV3');
         $this->fail('GoogleGeocodeException expected');
     } catch (GoogleGeocodeException $e) {
         $this->assertEquals("ResponseSubclassInvalid must inherit from GoogleGeocodeResponseV3", $e->getMessage(), 'Expected error message not received');
     }
     try {
         $this->service->setResponseClass('NotDefinedClass');
         $response = $this->service->geocode(self::ADDR_JWT_OFFICE);
         $this->assertType('GoogleGeocodeResponseV3', $response, 'Was not a GoogleGeocodeResponseV3');
         $this->fail('GoogleGeocodeException expected');
     } catch (Exception $e) {
         $this->assertEquals('Not a valid response class', $e->getMessage(), 'Expected error message not received');
     }
 }
<?php

/**
 * This example shows
 *
 * - How to bias a response towards a region
 * - How to bias a response towards a viewport
 */
require '../sdk/bootstrap.php';
require '../sdk/communicator/CurlCommunicator.php';
$service = new GoogleGeocodeServiceV3(new CurlCommunicator());
// Show that the API assumes "Portland, OR" for "Portland USA"
echo $service->geocode('Portland USA')->getFormattedAddress(), '<br>';
// Now geocode the state of Maine and bias results to its viewport
$maine = $service->geocode('Maine, USA');
$service->biasViewportByBoundsObject($maine->getViewport());
// Re-geocode "Portland USA"
echo $service->geocode('Portland USA')->getFormattedAddress(), '<br>';
// Establish an ambiguous location
$location = 'Toledo';
// Bias for the USA
$service->biasRegion('com');
echo $service->geocode($location)->getFormattedAddress(), '<br>';
// Bias for Spain
$service->biasRegion('es');
echo $service->geocode($location)->getFormattedAddress(), '<br>';
echo '<hr>', highlight_file(__FILE__, 1);
<?php

/**
 * This example shows
 *
 * - How the results can be counted
 * - How to iterate over a response with multiple results
 * - How to pull a specific address component name from a result
 */
require '../sdk/bootstrap.php';
require '../sdk/communicator/CurlCommunicator.php';
$service = new GoogleGeocodeServiceV3(new CurlCommunicator());
// Deliberately geocode an address that will yield multiple results
$response = $service->geocode('Springfield');
// Remember, GoogleGeocodeResponseV3 implements the Countable interface
if (count($response) > 1) {
    echo "The city of Springfield was found in: <br>";
    while ($response->valid()) {
        // Get the State name
        echo $response->getAddressComponentName(GoogleGeocodeResponseV3::ACT_ADMINISTRATIVE_AREA_LEVEL_1), '<br>';
        $response->next();
    }
} else {
    echo "Only one or no results";
}
echo '<hr>', highlight_file(__FILE__, 1);