Return to Snippet

Revision: 31570
at September 9, 2010 01:59 by adampatterson


Initial Code
$address = '1 Sir Winston Churchill Square';
$city = 'edmonton';
$province = 'alberta';
$country = 'canada';
$postalcode = 'T5J 2R7';

// Google Geo Address
$googleAddress = "http://maps.google.com/maps/geo?q=".urlencode($address) .'+'. urlencode($city) .'+'. urlencode($province).'+'. urlencode($postalcode).'+'. urlencode($country)."&output=xml";

// Retrieve the URL contents
$googlePage = file_get_contents($googleAddress);

// Parse the returned XML file
$xml = new SimpleXMLElement($googlePage);

// Parse the coordinate string
list($longitude, $latitude, $altitude) = explode(",", $xml->Response->Placemark->Point->coordinates);

// Output the coordinates
echo "Longitude: $longitude, Latitude: $latitude";

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

Initial Description


Initial Title
How to use Google HTTP Geocoding

Initial Tags
php, data, post, google, xml, code, csv, api

Initial Language
PHP