public function testViewportBiasing() { $location = 'Winnetka'; $swLat = 34.172684; $swLng = -118.604794; $neLat = 34.236144; $neLng = -118.500938; $params = array('language' => 'en', 'sensor' => 'false'); $format = 'json'; $params = array_merge($params, array('bounds' => "{$swLat},{$swLng}|{$neLat},{$neLng}")); $params = array_merge($params, array('address' => $location)); $this->service->biasViewport($swLat, $swLng, $neLat, $neLng); $this->assertEquals("http://maps.googleapis.com/maps/api/geocode/{$format}?" . http_build_query($params, '', '&'), $this->service->generateUrl($location, $format), 'URLs did not match'); $this->service->removeViewportBias(); $bounds = new stdClass(); $bounds->southwest = new stdClass(); $bounds->northeast = new stdClass(); $bounds->southwest->lat = $swLat; $bounds->southwest->lng = $swLng; $bounds->northeast->lat = $neLat; $bounds->northeast->lng = $neLng; $this->service->biasViewportByBoundsObject($bounds); $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);