/** * @author Carl McDade * @since 2013-05-09 * @version * * Use: go the the address bar and enter a place using the format * http://berlinto.com/test.php?place=berlin * http://berlinto.com/test.php?place=new jersey * http://berlinto.com/test.php?place=1 hampton rd. England * * Berlin, Germany */ $path = __DIR__ .'/path/to/zend/library'; set_include_path(get_include_path() . PATH_SEPARATOR . $path); require_once('Zend/Loader/StandardAutoloader.php'); $loader = new Zend\Loader\StandardAutoloader(array('autoregister_zf' => true)); $loader->registerNamespaces(array('Zend')); $loader->register(); use Zend\Http\Request; use Zend\Http\Client; class zftest{ protected $place; function __construct() { $this->place = $_GET['place']; } function zend_test() { $uri = 'http://maps.google.com/maps/api/geocode/json'; $address = urlencode($this->place); $sensor = 'false'; $request = new Request(); $request->setUri($uri); $request->setMethod('GET'); $client = new Client($uri); $client->setRequest($request); $client->setParameterGet(array('sensor'=>$sensor,'address'=>$address)); $response = $client->dispatch($request); if ($response->isSuccess()) { header('Content-Type: text/html; charset=utf-8'); print 'Your Request for:' . print_r($address, 1) . ''; print '' . print_r($response->getBody(), 1) . ''; } } } $maps = new zftest(); $maps->zend_test();
Popular just now
-
When dealing with Amazon Web Services using the command line for accessing the file system to configure the server using Putty is OK. But wh...
-
This was making me a little crazy today so I thought I would share. "Manual" PHP 5.5.x with WampServer Installing Windows (War...
-
One of my favorite pastimes is eavesdropping on programmers and developers while riding the commuter trains. You'd be amazed at the stuf...
ad1
Zend Framework and Google Maps API Example
When looking for a Senior PHP Developer position I get a lot of tests. Most of them I kindly refuse to do because they always involve array manipulation and have no real world context. They only show that the interviewer is not aware of what is real world. Sometimes the test is trying to solve problem that cannot be solved. I always ask who that works for them has solved the problem and can I meet them. Rather than babble on about the red flags that the answers to my question bring up I'll show my answer to a test. First because it was in the form of a spec. I like this. Secondly, because it involves using Google Maps API and object oriented PHP and Zend Framework I was happy to oblige. It was a useful real world test and harder than I expected because the Zend Framework v1 has horrible documentation and worse examples(none of them work). Zend Framework v2 has less. So after piecing together something that works I decided to share.
This is the code needed to connect to Google Maps API and display the results in JSON using ZF2 as a library.
More About:
Google Maps /
PHP5 /
Zend Framework
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment