public function testRegionBiasing() { $location = 'Toledo'; $region = 'es'; $params = array('language' => 'en', 'sensor' => 'false'); $format = 'json'; $params = array_merge($params, array('region' => $region)); $params = array_merge($params, array('address' => $location)); $this->service->biasRegion($region); $this->assertEquals("http://maps.googleapis.com/maps/api/geocode/{$format}?" . http_build_query($params, '', '&'), $this->service->generateUrl($location, $format), 'URLs did not match'); }
<?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);