<?php

function request_cache($url$dest_file$timeout=43200) {
  if(!
file_exists($dest_file) || filemtime($dest_file) < (time()-$timeout)) {
    if(
$_GET['debug']) echo $url;
    
$stream fopen($url,'r');
    
$tmpf tempnam('/tmp','YWS');
    
file_put_contents($tmpf$stream);
    
fclose($stream);
    
rename($tmpf$dest_file);
  }
}

function 
yahoo_geo($location) {
  
$q 'http://api.local.yahoo.com/MapsService/V1/geocode';
  
$q .= '?appid=rlerdorf&location='.rawurlencode($location);
  
$tmp '/tmp/yws_geo_'.md5($q);
  
request_cache($q$tmp43200);
  
libxml_use_internal_errors(true);
  
$xml simplexml_load_file($tmp); 
  
$ret['precision'] = (string)$xml->Result['precision'];
  foreach(
$xml->Result->children() as $key=>$val) {
    if(
strlen($val)) $ret[(string)$key] =  (string)$val;
  } 
  return 
$ret;
}

?>
<html>
<head>
<script type="text/javascript" src="http://api.maps.yahoo.com/v2.0/fl/javascript/apiloader.js"></script>
<style type="text/css">
#mapContainer { 
height: 600px; 
width: 600px; 

</style> 
<title>GeoCoding API Example</title>
</head>
<body>
<form action="/php/geo.php" method="GET">
<input type="text" size="80" name="location" />
</form>
<?php
if(!empty($_REQUEST['location'])) {
  
$a yahoo_geo($_REQUEST['location']);
  echo 
"<pre>"print_r($a); echo "</pre>";
}
?>
<div id="mapContainer"></div>
<script type="text/javascript">
var latlon = new LatLon(<?php echo $a['Latitude']?><?php echo $a['Longitude']?>);
var map = new Map("mapContainer", "rlerdorf", latlon, 3);
map.addTool( new PanTool(), true );
</script> 
<a href="/php/geo.phps">[Source Code]</a>
</body></html>