Getting Rich with PHP 5 |
 |
2025-02-25 |
 |
 |

15 |
 |
 |
Finally, a free geocoding API
REST Query to look up an address
http://local.yahooapis.com/MapsService/V1/geocode?appid=rlerdorf&location=Sunnyvale
Returned XML
We can parse it like this
<?php
$url = 'http://local.yahooapis.com/MapsService/V1/geocode';
$url .= '?appid=rlerdorf&location='.urlencode('Sunnyvale');
$xml = simplexml_load_file($url);
$ret['precision'] = (string)$xml->Result['precision'];
$ret['warning'] = (string)$xml->Result['warning'];
foreach($xml->Result->children() as $key=>$val) {
if(strlen($val)) $ret[(string)$key] = (string)$val;
}
echo "<pre>"; print_r($ret); echo "</pre>";
?>
Output