Posted By

adampatterson on 09/09/10


Tagged

php data post google xml code csv api addressbook explode 5


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

msheflin


How to use Google HTTP Geocoding


 / Published in: PHP
 

URL: http://www.adampatterson.ca/blog/2010/09/google-http-geocoding/

  1. $address = '1 Sir Winston Churchill Square';
  2. $city = 'edmonton';
  3. $province = 'alberta';
  4. $country = 'canada';
  5. $postalcode = 'T5J 2R7';
  6.  
  7. // Google Geo Address
  8. $googleAddress = "http://maps.google.com/maps/geo?q=".urlencode($address) .'+'. urlencode($city) .'+'. urlencode($province).'+'. urlencode($postalcode).'+'. urlencode($country)."&output=xml";
  9.  
  10. // Retrieve the URL contents
  11. $googlePage = file_get_contents($googleAddress);
  12.  
  13. // Parse the returned XML file
  14. $xml = new SimpleXMLElement($googlePage);
  15.  
  16. // Parse the coordinate string
  17. list($longitude, $latitude, $altitude) = explode(",", $xml->Response->Placemark->Point->coordinates);
  18.  
  19. // Output the coordinates
  20. echo "Longitude: $longitude, Latitude: $latitude";

Report this snippet  

You need to login to post a comment.