As well as Yahoo, the Google API is also very good. It's quite easy to convert any address fragment into a latitude and longitude in PHP as follows:
<?php
$file = file_get_contents("
http://maps.google.com/maps/geo?output=xml&q=".
urlencode($address). "&key=".GOOGLE_MAP_KEY);
/**
* A Bug? It says it's utf-8, but it's really not :(
*/
$xml = iconv("ISO-8859-1", "UTF-8", $file);
$xml = simplexml_load_string($xml);
if (!is_object($xml))
throw new Exception("Could not connect to geocode server. Sent argument: $address");
if ($xml->Response->Status->code == 200) {
$coordinates = (string) $xml->Response->Placemark->Point->coordinates;
list($latitude, $longitude) = explode(',', $coordinates);
} else {
throw new Exception("could not find $address");
}
?>
Note: The code is a partial extract from Crash At Mine:
http://www.crashatmine.org/snapshots/ (see lib/common_functions.php)
- Morgan