Skip to content

Instantly share code, notes, and snippets.

@jamsesso
Created December 23, 2010 22:08
Show Gist options
  • Save jamsesso/753613 to your computer and use it in GitHub Desktop.
Save jamsesso/753613 to your computer and use it in GitHub Desktop.
<?php
function toCoordinates($address)
{
$bad = array(
" " => "+",
"," => "",
"?" => "",
"&" => "",
"=" => ""
);
$address = str_replace(array_keys($bad), array_values($bad), $address);
$data = new SimpleXMLElement(file_get_contents("http://maps.google.com/maps/geo?output=xml&q={$address}"));
$coordinates = explode(",", $data->Response->Placemark->Point->coordinates);
return array(
"latitude" => $coordinates[0],
"longitude" => $coordinates[1]
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment