jueves, 15 de septiembre de 2011

PHP - Getting coordinates based on address


I have attached here the class and a test file so you can see how it works.
I plan to develop this class in the future that’s why it requires a Google Maps API key.
Here is the test file for it, just to make an impression on how it looks like :
  1. <?php
  2.  
  3. //include our class
  4. require_once(dirname(__FILE__) . ‘/class.googleHelper.php’);
  5.  
  6. //your Google Maps API key (you can get one for free from http://code.google.com/apis/maps/signup.html)
  7. $apiKey = ‘API_KEY_HERE’;
  8.  
  9. //init our object
  10. $obj = new googleHelper($apiKey);
  11.  
  12. //get coordinates and print the debug info
  13. $address = ‘Danmark, Sjælland, Hørve, Dragsholm Alle 4534′;
  14. print ‘For our "’ . $address . ‘" we have these data : ‘;
  15. print ‘<pre>’;
  16. print_r($obj->getCoordinates($address ));
  17.  
  18. ?>